Uitableview 从NIB加载TableViewCell时出现异常
我想从NIB加载TableViewCell,因此IssueTableCell.xib,我的代码如下:Uitableview 从NIB加载TableViewCell时出现异常,uitableview,xcode4.2,Uitableview,Xcode4.2,我想从NIB加载TableViewCell,因此IssueTableCell.xib,我的代码如下: static NSString *issueTableCellId = @"IssueTableCell"; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView d
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数据源必须从tableView返回一个单元格:cellForRowAtIndexPath
错误在哪里?因为编译器找不到reuseidentifier,所以出现错误&这意味着您的单元格为零 还要正确维护reuseidentifier,以便编译器可以重用它 您应该在dequeueReusableCellWithIdentifier后尝试此操作: 您必须检查nil,如果单元格为nil,则创建新单元格 像这样: 如果(单元格==nil) { //在这里创建新单元格
}我尝试过,但还是出现了例外情况:(