与ViewController中的UITableViewCell和UITableView交谈

Hop*_*ppo 0 iphone cocoa-touch uitableview ios5

我在storyboard视图控制器中设置了一个带有自定义单元格的表视图,并希望从我的ViewController类中控制它.我已经设置了ViewController作为我的委托.当我运行应用程序时,它只显示一个空列表,并且不会调用我的一个有标签的单元格.我希望在列表中看到这个标签.我已将数据源和委托连接到storyboard中的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
Run Code Online (Sandbox Code Playgroud)

Rob*_*ill 6

你的电话[tableView dequeueReusableCellWithIdentifier:]回复为零.这可能意味着您尚未在Interface Builder中设置自定义单元格的标识符(应为"StateCell").在IB中选择自定义单元格时,可以在"属性"检查器中找到此设置.