向 UITableView 添加数据时 iPhone 应用程序崩溃
我正在制作一个应用程序,但是当我尝试将数据添加到我的表视图时,我的应用程序挂在这里:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保
MyFileTableController
符合UITableViewDataSource
和UITableViewDelegate
。此外,您还将我假设的UIViewController
(基于名称的MyFileTableController
)添加到视图层次结构(这需要UIView
)。如果您需要显示MyFileTableController
,则需要以模态方式或通过其他方式(例如UINavigationController
)来执行此操作。Make sure
MyFileTableController
conforms toUITableViewDataSource
andUITableViewDelegate
. Also you are adding what I assume to be aUIViewController
(MyFileTableController
based on the name) to a view hierarchy (which requiresUIView
s). If you need to displayMyFileTableController
you need to do so modally or through some other means such as aUINavigationController
.