Xcode不编译“终止应用程序,由于未捕获的异常'NSInternalInconsistencyException'”
我有一个相当一个问题,试图在我的iOS应用程序中做一个简单的表视图。我从一些更复杂的源代码开始,但在追踪错误时,我发现它是Table View Controller的数据源方法中的错误。所以我用一个简单的导航控制器和一个表格视图做了一个非常简单的应用程序,我甚至还没有设法让它运行。Xcode不编译“终止应用程序,由于未捕获的异常'NSInternalInconsistencyException'”
这里是我的代码如下所示:
AppDelegate.m
#import "BIDAppDelegate.h"
#import "BIDFirstLevelController.h"
@implementation BIDAppDelegate
@synthesize window = _window;
@synthesize navController = _navController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
BIDFirstLevelController *firstView = [[BIDFirstLevelController alloc] initWithStyle:UITableViewStylePlain];
self.navController = [[UINavigationController alloc] initWithRootViewController:firstView];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
}
下面是引发问题的方法。为了测试它,我只想要一个显示3个单元格的列表,表示“你好”。在编译之前
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = @"Hello";
return cell;
}
Xcode的标记没有错误,但是当我尝试这样做,就说明这个控制台,它不会编译我的应用程序。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
有谁能告诉我这有什么问题吗?
更改此方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 44) reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"Hello";
return cell;
}
感谢那些工作,对不起,我在iOS开发一种新的。 – 2012-03-19 18:10:18
那好吧... – 2012-03-20 03:07:43
这是一个运行时错误.. – 2012-03-19 06:47:21