Reference from UITableViewCell to UITableView to UINavigationController
- by Nick
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..?