1
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    TRSocialCell *cell = (TRSocialCell *)[self.tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TRSocialCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

        __weak TREvent *eventFromParse;
        if (!isSearchingEvents){
            if ( [filteredArray[indexPath.section] count] == 0) {
                [cell displayForNoEvents];
                cell.selectedBackgroundView = bgCell;
                return cell;
            } else {
                eventFromParse = filteredArray[indexPath.section][indexPath.row];
            }
        }
        else eventFromParse = searched[indexPath.row];

        //Cover Image
        [eventFromParse.fileForCover getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
            if (!error) {
                eventFromParse.coverPicture = [UIImage imageWithData:data];
                cell.coverView.image = [UIImage imageWithData:data];

            } else {
                [TRAppDelegate displayInternetErrorForView:self.view];
            }

        }];

        cell.titleAutoLabel.text = [NSString stringWithFormat:@"%@",eventFromParse.title];
        cell.titleAutoLabel.fadeLength = 0;
        cell.titleAutoLabel.pauseInterval = 2.0f;
        [animatedLabels addObject:cell.titleAutoLabel];

        if (eventFromParse.location != nil) {
            cell.addressLabel.text = [NSString stringWithFormat:@"%@",eventFromParse.location.name];
        }

        [cell.titleAutoLabel setFont:[UIFont fontWithName:@"BigNoodleTitling" size:26]];
        [cell.titleAutoLabel setTextColor:[UIColor whiteColor]];
        [cell.addressLabel setFont:[UIFont fontWithName:@"BigNoodleTitling" size:18]];
        [cell.addressLabel setTextColor:[UIColor whiteColor]];
        [cell.dateLabel setFont:[UIFont fontWithName:@"BigNoodleTitling" size:18]];
        [cell.dateLabel setTextColor:[UIColor whiteColor]];

        cell.dateLabel.text = [NSString stringWithFormat:@"%@ - %@",[TRAppDelegate convertDateToDate:eventFromParse.date],[TRAppDelegate convertDateToTime:eventFromParse.date]];
        cell.selectedBackgroundView = bgCell;
    }

    return cell;
}

メモリが増えているので問題がありますが、何が見つからないのですか。別のセルにスクロールするたびに if (!cell) {} が呼び出され続けるのは正常ですか?

ビュー コントローラの割り当て解除でプロパティを nil に設定する必要がありますか?

このコードは何が漏れている可能性がありますか?

4

1 に答える 1

1

メモリが増えているので問題がありますが、何が見つからないのですか。別のセルにスクロールするたびに if (!cell) {} が呼び出され続けるのは正常ですか?

いいえ。新しく割り当てられたセルを再利用キューに入れませんでした。したがって、新しいセルを提供する必要があるたびに、基本的に新しい nib を RAM にロードします。あなたのやり方では、 newTRSocialCellは再利用識別子が何であるかを知りません - したがって、それらは明らかに再利用されません。

実装ファイル内に次のメソッドを実装してみてください。これにより、システムから要求されたときにTRSocialCellセルが返されるようになります。reuseIdentifier

- (NSString *)reuseIdentifier {
   return @"cell";
}

ところで:
'cell' は a の最も賢明な選択ではありませんreuseIdentifier。いつか別のタイプのセルを使用したい場合、再利用キューがめちゃくちゃになる可能性があります。識別子にクラス名を含めることをお勧めします。例えばTRSocialCellID

于 2013-10-04T20:59:03.590 に答える