简体   繁体   中英

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. When I remove the "[fileTable setDataSource:cont];", it doesn't crash.

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 UIView s). If you need to display MyFileTableController you need to do so modally or through some other means such as a UINavigationController .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM