【发布时间】:2012-05-03 10:16:44
【问题描述】:
我有一个问题,我在互联网上搜索了解决方案,但无济于事。我在故事板上的 Apress 开始 iOS 5 开发的第 10 章。
我认为这本书缺少一段简单的代码,因为我是第一次阅读,所以我不知道如何解决它。
我已经重新启动了两次项目,但在调试器中不断收到此错误:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath: 返回一个单元格:”
#import "BIDTaskListController.h"
@interface BIDTaskListController ()
@property (strong, nonatomic) NSArray *tasks;
@end
@implementation BIDTaskListController
@synthesize tasks;
- (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 world hostage",
@"Manicure",
nil];
}
- (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);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [tasks count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
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];
UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
cellLabel.text = task;
return cell;
}
@end
【问题讨论】:
-
你需要在你的界面文件中添加 UITableViewDataSource
-
将它作为协议添加到我的实现和头文件中,如下所示:@interface BIDTaskListController : UITableViewController
这不起作用...我还有我的应用程序 delegate.h 和.m; bidviewcontroller.h 和 .m;我应该向他们添加什么吗?
标签: ios uitableview sigabrt uncaught-exception