I have set up a table view with a custom cell in my storyboard view controller, and want to control it from my ViewController class. I have set up ViewController to act as my delegate. When I run the app it just displays an empty list and doesn’t call my one cell which has a label on it. I’d expect to see this label in the list. I’ve wired the datasource and delegate to ViewController in storyboard. My .h and .m files are as below, edited for simplicity.
When I run it I get 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' So it looks like the delegation isn’t working properly. What have I missed? Do I need to connect the cell to anything?
@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
Your call to
[tableView dequeueReusableCellWithIdentifier:]is returning nil. This might mean that you haven’t set the identifier for your custom cell in Interface Builder (should be ‘StateCell’). You can find this setting in the Attributes inspector when you select the custom cell in IB.