【发布时间】:2011-10-26 20:13:42
【问题描述】:
我在我的故事板视图控制器中设置了一个带有自定义单元格的表格视图,并希望从我的 ViewController 类中控制它。我已经设置 ViewController 作为我的代表。当我运行该应用程序时,它只会显示一个空列表,并且不会调用我的一个带有标签的单元格。我希望在列表中看到这个标签。我已将数据源和委托连接到情节提要中的 ViewController。我的 .h 和 .m 文件如下,为简单起见进行了编辑。
当我运行它时,我得到了'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 所以看起来委托工作不正常。我错过了什么?我需要将电池连接到任何东西吗?
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end
@implementation ViewController
...
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReportItem"];
return cell;
}
@end
【问题讨论】:
-
@Srikar。在发布之前,我已尽可能彻底地研究了这一点。那为什么要记下来呢?让我们的菜鸟休息一下。
-
为什么假设我把它标记下来了?没做,伙计...我只是编辑了你的问题,让它读起来更好。
标签: iphone cocoa-touch uitableview ios5