0

NIBからTableViewCellをロードしたいので、IssueTableCell.xibと私のコードは次のとおりです。

static NSString *issueTableCellId = @"IssueTableCell";

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:issueTableCellId];
NSInteger index = indexPath.row;

NSDictionary *d = [data objectAtIndex:indexPath.row];

UILabel *titleLabel = (UILabel *)[cell viewWithTag:101];
titleLabel.text= [d objectForKey:@"Name"];


UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
imageView.image=nil;

[self setCoverOfIssueAtIndex:index completionBlock:^(UIImage *img) {
    dispatch_async(dispatch_get_main_queue(), ^{
        UITableViewCell *cell = [table_ cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];
        UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
        imageView.image=img;
    });
}];

NKLibrary *nkLib = [NKLibrary sharedLibrary];
NKIssue *nkIssue = [nkLib issueWithName:[self nameOfIssueAtIndex:index]];
UIProgressView *downloadProgress = (UIProgressView *)[cell viewWithTag:102];
UILabel *tapLabel = (UILabel *)[cell viewWithTag:103];
if(nkIssue.status==NKIssueContentStatusAvailable) {
    tapLabel.text=@"TAP TO READ";
    tapLabel.alpha=1.0;
    downloadProgress.alpha=0.0;
} else {
    if(nkIssue.status==NKIssueContentStatusDownloading) {
        downloadProgress.alpha=1.0;
        tapLabel.alpha=0.0;
    } else {
        downloadProgress.alpha=0.0;
        tapLabel.alpha=1.0;
        tapLabel.text=@"TAP TO DOWNLOAD";
    }

}
return cell; }

私の例外は

UITableView dataSourceは、tableView:cellForRowAtIndexPathからセルを返す必要があります

エラーはどこにありますか?

4

1 に答える 1

0

コンパイラが再利用識別子を見つけることができないため、エラーが発生します。これは、セルがnilであることを意味します

また、reuseidentifier を適切に維持して、コンパイラが再利用できるようにします。

dequeueReusableCellWithIdentifier の後にこれを試す必要があります。

nil をチェックする必要があり、セルが nil の場合は、次のように新しいセルを作成します。

if(セル == ゼロ)

{

//ここに新しいセルを作成...

}

于 2012-11-10T13:19:03.267 に答える