简体   繁体   中英

What method will be called when Navigation back button is clicked -IOS?

This questions look repeated, but I din't got proper solution for my problem. In my case, Once I clicked back button I want to hide the navigation bar. For eg View1 pushed view2, view2 will have navigation bar,once I clicked back it brings me back to view 1 it should not contain navigation bar I need to hide it. I tried with viewWillDisappear method in view 2 to hide, it worked but if I have more view and I'm pushing each view from view1 if I click back button,navigation bar should hide in view1. So is anyway is there to know in view 1 itself that other view is popped. I tried viewwillappear method in view1 its not called. What can I do here.?

This method got called once I initially load view1, not after popping view2..

    - (void) viewWillAppear : (BOOL)animated
{
    [root_obj.navigationController setNavigationBarHidden:YES animated:YES];
}

This is how I am pushing view 2..

[root_obj.navigationController pushViewController:view2 animated:NO];

thanks in Advance

i think, u have forgot to call viewWillAppear: method of super class.

-(void) viewWillAppear : (BOOL)animated
{

    [super viewWillAppear:animated];

    [root_obj.navigationController setNavigationBarHidden:YES animated:YES];
}

Why don't you hide the NavigationBar in View1's ViewDidAppear method

Edit

I am not sure what the problem with your code but you can do these kind of things in ViewWillAppear or ViewDidAppear methods for more information UIViewController Class Reference and check ViewWillAppear or ViewDidAppear

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM