您的位置:首页 > 移动开发

SecondiosAppTutorial--学习笔记

2016-03-02 18:25 288 查看
自学SecondiosAppTutorial过半,运行程序报错了,最终问题找到,英文文档读起来很有挫败感,但耐心就能发现问题,Xcode的问题提示很明确清楚。如下:

/*Debug 输出的报错信息,显示TableView cell为空值*/
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'


tableView 没有返回值,cell 值为null。设计TableView的实现方法在MasterViewController.m中,先从代码着手找问题。

1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
2     /*UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
3
4     NSDate *object = self.objects[indexPath.row];
5     cell.textLabel.text = [object description];
6     return cell;*/
7     static NSString *CellIdentifier = @"BirdSightingCell";/*BirdSightingCell是表格中cell的Identifier属性名字*/
8
9     static NSDateFormatter *formatter = nil;
10     if (formatter == nil) {
11         formatter = [[NSDateFormatter alloc] init];
12         [formatter setDateStyle:NSDateFormatterMediumStyle];
13     }
14     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
15       NSLog(@"111222%@",cell);
16     BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row];
17     [[cell textLabel] setText:sightingAtIndex.name];
18     [[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate *)sightingAtIndex.date]];
19     NSLog(@"111222%@",cell);
20     return cell;
21 }


cell没有值,依次输出信息15、19输出内容都是null。那么第7行就很可能出错了。BirdSightingCell是 TableView中cell的Identifier的属性值,发现自己的表格中的值竟然是cell。恍然大悟。具体位置如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: