views:

561

answers:

1

I have a stack of UITableViews managed by a UINavigationController. When I try calling indexPathForSelectedRow on any of the previous UITableViews, I always get nil:

NSEnumerator *e = [[navigationController viewControllers] objectEnumerator];
UITableViewController *controller;
while (controller = [e nextObject]) {
    NSIndexPath *selectedIndexPath = [[controller tableView] indexPathForSelectedRow]; // always nil
    // ...
}

I can't find anything about this behavior in Apple's docs; is it intentional? If so, is there another way to do what I'm trying to do, without me having to resort to manually managing a redundant mySelectedIndexPath instance variable inside didSelectRowAtIndexPath or somesuch?

A: 

A non-visible view in a UINavigationController stack can be unloaded at any time, therefore you can't rely on the state of non-visible views.

It's quite possible that the UITableViewController you're referencing would have already unloaded its table view, in which case calling [controller tableView] will instantiate a new view.

Darren
Interesting; thanks for the info. Is this documented anywhere?
See the Memory Management section in the UIViewController documentation.
Darren