I am pushing a view controller ( DetailView
) via my table view's delegate class, MyClass
. MyClass
acts as a delegate for a table view in MasterView
. Im attempting to push DetailView
from the "didSelectRowAtIndexPath:" method of MyClass
but every time DetailView
is pushed the back button leading back to MasterView
is disabled.
My Code for pushing the view:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!detailViewController) {
detailViewController = [[DetailViewController alloc] init];
}
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.navigationController pushViewController:detailViewController animated:YES];
}
Instead of [appDelegate.navigationController pushViewController:detailViewController animated:YES];
, use [self.navigationController pushViewController:detailViewController animated:YES];
.
It sounds like the appDelegate
's nav controller is a different instance to the MasterView
's one, which would explain the weird behaviour.
Using self.navigationController
pushes another view controller on top of the MasterView
nav controller's stack.
Sounds like you need to get your push call back to your MasterView.
You can either do this by setting a protocol in MyClass and firing the push call back through the delegate from MyClass to MasterView (which makes for a strange back and forth delegation pattern), using the notification center (might be useful if multiple views need to know this push is happening), or by passing in a reference to the MasterView when you initialize MyClass and use that for the push.
No matter what you choose, trying to use the AppDelegate's nav controller will definitely give you strange results.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.