views:

262

answers:

2

I have a UITableViewController which in it's tableView:didSelectRowAtIndexPath method, sets up a view controller, and calls

[self.navigationController pushViewController: viewController animated:YES].

When i select a row in the root controller, the second viewController loads but is empty - table view loads but has no data. Here, tableView:numberOfRowsInSection is not called.

When i return to the top level, and then select the same row again, the view loads correctly - method called.

Why would the table view not call the delegate methods on the fist attempt, but call them on the second?

Am i missing something obvious?

Thanks

A: 

When you say:

When i select a row in the root controller, the second viewController loads but is empty.

Do you mean that the view is present but contains no data or do you mean that the table disappears to be replaced by blank/empty view?

If it is the former, then you need to make sure that the second level view controller has proper access to the data before you push it on the stack so that it can populate its view.

If it is the latter, it sounds like your second level view controller is not properly initializing its view the first time it is called. If you use a nib, check in Interface Builder that the controller has an outlet pointing to the view. If you create the view programmatically, check that the view is being initialized properly before it is called to display.

TechZen
Sorry should have been clearer. The table view loads but contains no data. How would I check about correct data access? My view is supposed to get my data from an array (which it does when I load the view a second time).
joec
The problem will be wherever the second level view controller gets the data array. If it is external check where the controller is assigned the data or when is accesses. If it generates the data internally, make sure the method that does so is called before the view appears.
TechZen
+1  A: 

Solved by using initWithNibName instead of initWithStyle - knew it would be something obvious.

Thanks

joec