[英]Should Xcode Storyboard support segues from a UITableView with 'dynamic prototype' cells?
[英]Using Xcode 5 Storyboards to Build Dynamic TableViews with Prototype Table View Cells
我正在嘗試按照本教程進行操作,但是我得到的是空表。
首先,教程正在使用
{
CarTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
}
我遇到了一個錯誤:
2013-11-12 11:29:35.940 TableViewStory[14940:70b] *** Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with
identifier carTableCell - must register a nib or a class for the identifier or connect a
prototype cell in a storyboard'
所以我補充說:
[self.tableView registerClass:[CarTableViewCell class]
forCellReuseIdentifier:@"carTableCell"];
在我的viewDidLoad上。 添加registerClass之后,我可以構建我的應用程序。 但是我正在空表。
謝謝。
您需要適當地實現cellForRowAtIndexPath方法:
- (UITableViewCell *)tableView:(UITableView *)iTableView cellForRowAtIndexPath:(NSIndexPath *)iIndexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [iTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
// Customize your cell
return cell;
}
您沒有為重用標識符CellIdentifier注冊筆尖或類。 您正在使用下面的一塊
CarTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
替換為
CarTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
我重新編寫了教程,一切正常。
不管怎么說,還是要謝謝你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.