I’m doing a SplitViewController with a TableViewController in the Detail and Master.
I get this message in the console when I try to run:
2012-10-06 16:42:05.304 BaylorNotes7[3040:c07] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:5471
2012-10-06 16:42:05.306 BaylorNotes7[3040:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
The problem is in the DetailViewController.m:
#import "DetailViewController.h"
#import "NSString+HTML.h"
typedef enum { SectionHeader, SectionDetail } Sections;
typedef enum { SectionHeaderTitle, SectionHeaderDate, SectionHeaderURL } HeaderRows;
typedef enum { SectionDetailSummary } DetailRows;
@implementation DetailTableViewController
@synthesize item, dateString, summaryString;
#pragma mark -
#pragma mark Initialization
- (id)initWithStyle:(UITableViewStyle)style {
if ((self = [super initWithStyle:style])) {
}
return self;
}
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
// Super
[super viewDidLoad];
// Summary
if (item.summary) {
self.summaryString = [item.summary stringByConvertingHTMLToPlainText];
} else {
self.summaryString = @"[No Summary]";
}
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
switch (section) {
case 0: return 1;
default: return 1;
}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"DetailCell"];
// Display
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.font = [UIFont systemFontOfSize:15];
if (item) {
// Item Info
NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
// Display
switch (indexPath.section) {
case SectionHeader: {
// Header
switch (indexPath.row) {
case SectionHeaderTitle:
cell.textLabel.font = [UIFont fontWithName:@"Times New Roman" size:20];
cell.textLabel.text = itemTitle;
break;
}
break;
}
case SectionDetail: {
// Summary
cell.textLabel.text = summaryString;
cell.textLabel.numberOfLines = 100; // Multiline
cell.textLabel.font = [UIFont fontWithName:@"Times New Roman" size:20];
break;
}
}
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == SectionHeader) {
// Regular
return 60;
} else {
// Get height of summary
NSString *summary = @"[No Summary]";
if (summaryString) summary = summaryString;
CGSize s = [summary sizeWithFont:[UIFont systemFontOfSize:20]
constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT) // - 40 For cell padding
lineBreakMode:UILineBreakModeWordWrap];
return s.height; // Add padding
}
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Open URL
if (indexPath.section == SectionHeader && indexPath.row == SectionHeaderURL) {
if (item.link) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:item.link]];
}
}
// Deselect
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
I’m pretty sure the problem is somewhere in the Table declaration. In case anyone is wondering, I followed the MWFeedParser tutorial to get this. Any help is appreciated!
Select the prototype cell in the storyboard, go to the Attributes inspector, type it into the Identifier field.
and set the proper identifier.
Credit:
http://www.raywenderlich.com/forums/viewtopic.php?f=13&t=4217