2010-03-11 180 views
0

重现步骤:
1.创建一个标签栏应用程序名为“TestApp”
2.添加新的文件,一个UIViewController子类与所谓的“表”
3.打开了MainWindows一个XIB的用户界面。 xib,单击第二个标签栏项目,然后在Inspector中将NIB名称从“SecondView”更改为“Table”。保存并关闭。
4.打开Table.xib并在视图顶部拖动一个TableView。现在将TableView的dataSource和委托出口链接到Table.xib文件的所有者。
5.将以下代码添加到Table.m:标签栏应用程序上的TableView?应用程序崩溃

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
NSLog(@"Returning num sections"); 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
NSLog(@"Returning num rows"); 
return 1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
NSLog(@"Trying to return cell"); 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
} 
cell.text = @"Hello"; 
NSLog(@"Returning cell"); 
return cell; 
} 

6.Run的应用程序并选择第二个选项卡栏项目。

如果我从一个基于视图的应用程序开始,向它添加一个TableView,将这些插座链接到文件的所有者并添加这段代码,它都可以正常工作。 我在做什么错?为什么应用程序崩溃?

回答

0

在界面构建器中,将NIB名称更新为表后,单击检查器的标识选项卡(最后一个选项卡)。然后将类标识更新为“表”。