2012-11-09 53 views
0
加載TableViewCell當

我想從NIB加載TableViewCell所以IssueTableCell.xib和我的代碼是在這裏:異常來自NIB

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) { 
    [email protected]"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; 
     [email protected]"TAP TO DOWNLOAD"; 
    } 

} 
return cell; } 

和我的例外是

UITableView的數據源必須返回一個細胞tableView:cellForRowAtIndexPath

哪裏出錯?

回答

0

的錯誤出現,因爲編譯器無法找到reuseidentifier &這意味着你的細胞是零

也保持reuseidentifier適當所以編譯器可以重複使用。

你應該dequeueReusableCellWithIdentifier後試試這個:

你必須檢查零,如果電池是零,然後創建新的細胞 這樣的:

如果(細胞==零)

{

//這裏創建新的細胞...

}

+0

我嘗試了但仍然發生異常:( –

相關問題