Reference from UITableViewCell to UITableView to UINavigationController
Posted
by Nick
on Stack Overflow
See other posts from Stack Overflow
or by Nick
Published on 2010-03-13T06:17:06Z
Indexed on
2010/03/13
6:25 UTC
Read the original article
Hit count: 695
If the user taps and holds on a Foo table view cell for 2 seconds, a modal view should be shown. The modal view is also displayed when a new Foo is added to the cell. The modal view's delegate protocol is implemented by the parent UITableView subclass.
My tap and hold detection code is in the Foo UITableViewCell class.
I'm having difficulty referencing the parent tableview's navigation controller to display the modal view.
FooModalViewController *modalController = [[FooModalViewController alloc] initWithNibName:@"FooModalViewController" bundle:nil];
FooTableViewController *tableView = (FooTableViewController *) self.superview;
foo.delegate = tableView;
Seems OK but I'm having problems referencing the navigation controller that contains the tableview.. The code below builds OK but throws an exception - NSOBject DoesNotRecognizeSelector.
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:modalController];
[[tableView.navigationController] presentModalViewController:navigationController animated:YES];
I think that perhaps my design is flawed..?
© Stack Overflow or respective owner