重现步骤:
1. 创建一个名为“TestApp”的标签栏应用程序
2. 添加新文件,一个带有名为“Table”的 XIB 用户界面的 UIViewController 子类
3. 打开 MainWindows.xib,单击第二个标签栏项目并在Inspector 将 NIB 名称从“SecondView”更改为“Table”。保存并关闭。
4. 打开 Table.xib 并在视图顶部拖动一个 TableView。现在将 TableView 的 dataSource 和 delegate 出口链接到 Table.xib 文件的所有者。
5. 将以下代码添加到 Table.m 中:
- (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.运行应用程序并选择第二个标签栏项目。
如果我从一个基于视图的应用程序开始,向它添加一个 TableView,将插座链接到文件的所有者并添加那段代码,一切都很好。我究竟做错了什么 ?为什么应用程序崩溃?