向 UITableView 添加数据时 iPhone 应用程序崩溃

发布于 2024-12-15 01:57:15 字数 698 浏览 2 评论 0原文

我正在制作一个应用程序,但是当我尝试将数据添加到我的表视图时,我的应用程序挂在这里:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));

这是我的代码:

UITableView *fileTable = [[UITableView alloc] initWithFrame:CGRectMake(10, 46, 300, 369) style:UITableViewStylePlain];

[fileTable setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Canvas_Tile.png"]]];

[fileTable setDelegate:self];

MyFileTableController *cont = [[MyFileTableController alloc] init];

[fileTable setDataSource:cont];

[self.view addSubview:fileTable];

是的,我包括 UITableViewDelegate 并且我的所有类(包括我的应用程序委托)都很好。当我删除“[fileTable setDataSource:cont];”时,它不会崩溃。

I'm making an app, but when I try to add data to my table view, my app hangs here:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));

Here's my code:

UITableView *fileTable = [[UITableView alloc] initWithFrame:CGRectMake(10, 46, 300, 369) style:UITableViewStylePlain];

[fileTable setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Canvas_Tile.png"]]];

[fileTable setDelegate:self];

MyFileTableController *cont = [[MyFileTableController alloc] init];

[fileTable setDataSource:cont];

[self.view addSubview:fileTable];

Yes, I am including the UITableViewDelegate and all of my classes including my app delegate are fine. When I remove the "[fileTable setDataSource:cont];", it doesn't crash.

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

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

发布评论

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

评论(1

勿忘心安 2024-12-22 01:57:15

确保 MyFileTableController 符合 UITableViewDataSourceUITableViewDelegate。此外,您还将我假设的 UIViewController (基于名称的 MyFileTableController)添加到视图层次结构(这需要 UIView)。如果您需要显示MyFileTableController,则需要以模态方式或通过其他方式(例如UINavigationController)来执行此操作。

Make sure MyFileTableController conforms to UITableViewDataSource and UITableViewDelegate. Also you are adding what I assume to be a UIViewController (MyFileTableController based on the name) to a view hierarchy (which requires UIViews). If you need to display MyFileTableController you need to do so modally or through some other means such as a UINavigationController.

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