[英]iPhone App Crashes when adding data to UITableView
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. 是的,我包括UITableViewDelegate,包括我的应用程序委托在内的所有类都很好。 When I remove the "[fileTable setDataSource:cont];", it doesn't crash.
当我删除“ [fileTable setDataSource:cont];”时,它不会崩溃。
Make sure MyFileTableController
conforms to UITableViewDataSource
and UITableViewDelegate
. 确保
MyFileTableController
符合UITableViewDataSource
和UITableViewDelegate
。 Also you are adding what I assume to be a UIViewController
( MyFileTableController
based on the name) to a view hierarchy (which requires UIView
s). 另外,您
MyFileTableController
我假设是UIViewController
(基于名称的MyFileTableController
)添加到视图层次结构(需要UIView
)。 If you need to display MyFileTableController
you need to do so modally or through some other means such as a UINavigationController
. 如果需要显示
MyFileTableController
,则需要以模态或通过其他方式(例如UINavigationController
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.