我在使用 iphone 模拟器的 xcode4 中得到了这个异常:
Terminating app due to uncaught exception 'NSInternalInconsistencyException'
如果您在 cellForRowAtIndex 方法中没有返回任何对象(返回 0),这似乎是造成的。但我已经准备好归还牢房了。
谁能看到可能导致此错误的原因?这是一堆截图:
控制器配置:
原型细胞
注意单元:
故事板:
完全错误:
**Assertion failure in -[UITableView
_createPreparedCellForGlobalRow:withIndexPath:],
/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
2012-07-30 14:34:16.660 Simple Storyboard[263:f803] Terminating app due
to uncaught exception 'NSInternalInconsistencyException',
reason: 'UITableView dataSource must return a cell from
tableView:cellForRowAtIndexPath:'**
这是代码:
#import "LWWBidTaskListController.h"
@interface LWWBidTaskListController ()
@property (strong, nonatomic)NSArray *tasks;
@end
@implementation LWWBidTaskListController
@synthesize tasks;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tasks = [NSArray arrayWithObjects: @"Walk the dog", @"URGENT:Buy milk", @"Clean hidden lair", @"Invent miniature dolphins", @"Find new henchmen", @"Get revenge on do-gooder heroes", @"URGENT: Fold laundry", @"Hold entire hold hostage", @"Manicure", nil];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.tasks = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
//return 0;
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
//return 0;
return [tasks count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath//populates each cell
{
//static NSString *CellIdentifier = @"Cell";
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *identifier = nil;
NSString *task = [self.tasks objectAtIndex:indexPath.row];
NSRange urgentRange = [task rangeOfString:@"URGENT"];
if (urgentRange.location == NSNotFound)
{
identifier = @"plainCell";
}
else
{
identifier = @"attentionCell";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
// Configure the cell...
UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
cellLabel.text = task;
return cell;
}
该错误是什么意思,我该如何解决?