今天在 用故事板布局的过程中,新建一个FKAuthorTableViewController继承与UITableViewController,然后沿用系统自带的cellForRow代理方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
// Configure the cell...
return cell;
}
然后运行程序,崩溃信息为:*** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableView.m:6573.
解决方案为 用
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
替代
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
原因如下:
My bad! It seems to be you are using dequeueReusableCellWithIdentifier:forIndexPath:
method for dequeueing cell. Please try dequeueReusableCellWithIdentifier:
instead and it should work.
dequeueReusableCellWithIdentifier:forIndexPath:
expects a nib file or a registered class for dequeueing cells but you are using storyboard prototype cell. And dequeueReusableCellWithIdentifier:
is guaranteed to return a cell from storyboard if you use correct identifier.
意思为:预想加载宇哥nib文件或者注册的单元格,但是你用故事板生成的单元格,第二个方法可以保证在identifier正确的情况从故事板返回一个单元格。