标签栏应用程序上的 TableView ?应用程序崩溃

发布于 2024-08-25 00:31:25 字数 1157 浏览 4 评论 0原文

重现步骤:
1. 创建一个名为“TestApp”的选项卡栏应用程序
2. 添加新文件,一个带有名为“Table”的 XIB 用户界面的 UIViewController 子类
3. 打开MainWindows.xib,单击第二个选项卡栏项目,然后在检查器中将NIB 名称从“SecondView”更改为“Table”。保存并关闭。
4. 打开 Table.xib 并将 TableView 拖到视图顶部。现在将 TableView 的数据源和委托出口链接到 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,将出口链接到文件的所有者并添加那段代码,那么一切都可以正常工作。 我做错了什么?为什么应用程序崩溃?

Steps to reproduce:
1. Create a Tab Bar Application called "TestApp"
2. Add new file, a UIViewController subclass with a XIB user interface called "Table"
3. Open up MainWindows.xib, click on the Second tab bar item and in Inspector change the NIB Name from "SecondView" to "Table". Save and close.
4. Open up Table.xib and drag a TableView on top of the view. Now link the dataSource and delegate outlets of the TableView to the Table.xib File's Owner.
5. Add the following code to 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.Run the application and select the Second tab bar item.

If I start with a View-based application, add a TableView to it, link the outlets to the File's owner and add that piece of code it all works just fine.
What am I doing wrong ? Why is the application crashing ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤者何惧 2024-09-01 00:31:25

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

In Interface Builder, after you've updated the NIB Name to Table, click on the Identity tab of the inspector (the last tab). Then updated the Class Identity to 'Table'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文