0

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.

George Morgan
  • 669
  • 10
  • 23

1 Answers1

1

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.

Joe
  • 56,979
  • 9
  • 128
  • 135
  • MyFileTableController is the data source for my table view (a simple view subclass for UITableView) which I have already added to my view. Without the "[fileTable setDataSource:cont];" line, it doesn't crash. When I try to populate my table view with data, it crashes. – George Morgan Nov 11 '11 at 20:20
  • You need to add the crash details. If it is just an EXC_BAD_ACCESS then you need to enable zombies. – Joe Nov 11 '11 at 20:21
  • Sorry: The debugger outputs nothing, but the crash is EXC_BAD_ACCESS. What is "zombies," and how do I enable it? – George Morgan Nov 11 '11 at 20:25
  • NSZombie [what, when and why](http://stackoverflow.com/questions/4168327/what-is-nszombie) ... [where and how](http://stackoverflow.com/questions/2190227/how-do-i-set-nszombieenabled-in-xcode-4) – Joe Nov 11 '11 at 20:50