从NIB加载TableViewCell时异常



我想从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; }

我的例外是

uitaiteView dataSource必须从tableview返回单元格:cellforrowatIndExpath

错误在哪里?

出现错误是因为编译器找不到REUSEDIDIFIER&这意味着您的单元为nil

还适当地维护重复使用者,以便编译器可以重复使用。

您应该在DequeueReusableCelleWithIdentifier之后尝试一下:

您必须检查零零,如果是零,则创建新单元格这样:

if(cell == nil)

{

//在这里创建新单元...

}

最新更新