2010-04-09 1 views
0

테이블 뷰에서 이미지를 스크롤하는 동안 문제가 있습니다.이미지가있는 테이블 뷰를 스크롤하는 동안 신호 "0"오류가 발생했습니다.

신호 "0"오류가 발생했습니다.

나는 그것이 일부 메모리 문제로 인한 것이라고 생각하지만 정확한 오류를 찾을 수는 없습니다. 다음과 같이 코드는

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [travelSummeryPhotosTable dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    {   
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease]; 

    } 

    //Photo ImageView 
    UIImageView *photoTag = [[UIImageView alloc] initWithFrame:CGRectMake(5.0, 5.0, 85.0, 85.0)]; 

    NSString *rowPath =[[imagePathsDictionary valueForKey:[summaryTableViewDataArray objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 

    photoTag.image = [UIImage imageWithContentsOfFile:rowPath]; 
    [cell.contentView addSubview:photoTag]; 

    [photoTag release]; 

    // Image Caption 
    UILabel *labelImageCaption = [[UILabel alloc] initWithFrame:CGRectMake(110.0, 15.0, 190.0, 50.0)]; 
    labelImageCaption.textAlignment = UITextAlignmentLeft; 
    NSString *imageCaptionText =[ [imageCaptionsDictionary valueForKey:[summaryTableViewDataArray objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 
    labelImageCaption.text = imageCaptionText; 
    [cell.contentView addSubview:labelImageCaption]; 
    [labelImageCaption release]; 

    return cell; 

} 

감사합니다 사전에있다.

답변

2

신호 "0"오류은 일반적으로 메모리가 부족하여 응용 프로그램이 다운 된 것을 의미합니다.

문제는 다음과 같습니다. cellForRowAtIndexPath 메서드가 호출 될 때마다 셀 하위 뷰를 만들어 셀에 추가합니다. 할당 된 모든 UI 요소가 메모리에서 멈추고 결국 응용 프로그램이 종료됩니다. 빠른 회신

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [travelSummeryPhotosTable dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    {   
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease]; 

     UIImageView *photoTag = [[UIImageView alloc] initWithFrame:CGRectMake(5.0, 5.0, 85.0, 85.0)]; 
     photoTag.tag = 10; 
     [cell.contentView addSubview:photoTag]; 
     [photoTag release]; 

     UILabel *labelImageCaption = [[UILabel alloc] initWithFrame:CGRectMake(110.0, 15.0, 190.0, 50.0)]; 
     labelImageCaption.tag = 11; 
     labelImageCaption.textAlignment = UITextAlignmentLeft; 
     [cell.contentView addSubview:labelImageCaption]; 
     [labelImageCaption release]; 
    } 

    //Photo ImageView 
    NSString *rowPath =[[imagePathsDictionary valueForKey:[summaryTableViewDataArray objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 
    UIImageView* photoTag = (UIImageView*)[cell.contentView viewWithTag:10]; 
    photoTag.image = [UIImage imageWithContentsOfFile:rowPath]; 

    // Image Caption 
    UILabel *labelImageCaption = (UILabel*)[cell.contentView viewWithTag:11]; 
    NSString *imageCaptionText =[ [imageCaptionsDictionary valueForKey:[summaryTableViewDataArray objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 
    labelImageCaption.text = imageCaptionText; 

    return cell; 
} 
+0

감사 블라디미르! : 나중에 단지 설정 내용을을 만들 때 -

한 번만 세포의 서브 뷰를 작성해야 문제를 해결하기 위해 코드를 업데이트했습니다. 응용 프로그램이 충돌하지 않지만 TableView의 스크롤이 매우 느립니다. 런타임에 문서 디렉토리에서 이미지를로드하고 있습니다. 느린 스크롤링의 이유입니까? 이미지를 저장하는 표준 방법은 무엇입니까? 이미지 배열을 만들고 액세스해야합니까? 이미지의 크기 또한 스크롤 속도에 영향을 줍니까? 다른 클래스의 메모리 누수로 인해 느린 스크롤이 발생합니까? –

+0

에서 Apple의 LazyTableImages 샘플을 확인하십시오. http://developer.apple.com/iphone/library/samplecode/LazyTableImages/Introduction/Intro.html – Vladimir

관련 문제