0

テーブルビューで画像をスクロールしているときに問題が発生しました。

Signal "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;

}   

前もって感謝します。

4

1 に答える 1

2

Signal "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;
}   
于 2010-04-09T12:42:20.553 に答える