Reputation: 114
I need to detect the Navigation BackBarButton and View while switching tab on Tab based application . How can i achieve this. i need code sample
Upvotes: 1
Views: 143
Reputation: 305
NavigationBar is drawn after the viewController that is pushed loads. Also, that modalViewController's sit ontop of the topViewController in the 'stack' on the navigationController. and to detect a UINavigationController's back button press is by verifying that the current view controller is not present in the in the navigation controller's view controller stack. It can safely check this condition in - (void)viewDidDisappear:(BOOL)animated as logically, by the time that method is called it would be extremely likely that the view controller was removed from the stack. Switching view or the same view can be detect by using navigationController.topViewController and backBarButtonItem is triggered by using isKindOfClass. Here is the example that works for me.
- (void)viewDidDisappear:(BOOL)animated{
if ([self.navigationController.topViewController isKindOfClass:[SDWebImageRootViewController class]]) {
NSLog(@"Is kind of");
//condition goes here
}
if (!self.navigationController.topViewController) {
NSLog(@"Is kind of topViewController");
//condition goes here
}
}
Upvotes: 1