Hide Navigation Controller Back Button iOS 7

2019-03-15 02:56发布

问题:

I have tried to hide the back button in my navigation controller by adding the following lines to my viewDidLoad method. Many other previous answers on SO have said this works, so I don't know what my problem is? Maybe something new with iOS 7 / Xcode 5?

self.navigationItem.hidesBackButton = YES;
self.navigationController.navigationItem.hidesBackButton = YES;

回答1:

I too had faced similar issue. This will work only when you have not customized your Navigation bar. Either one of the below one will work.

[self.navigationItem setHidesBackButton:YES animated:YES];   OR
[self.navigationItem setHidesBackButton:YES];

Please check whether your getting "Back" in iOS 7, then the above will work.

Hope this will help you to identify the issue



回答2:

In UINavigationController we can hide Like this:

[self.navigationItem setHidesBackButton:YES animated:YES];

And In UITabBarController we can Hide Like this:

self.tabBarController.navigationItem.hidesBackButton = YES;


回答3:

self.navigationItem.leftBarButtonItem = 
 [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]];


回答4:

Use following code :

[self.navigationItem setHidesBackButton:YES animated:YES]; // hide back button

[self.navigationItem setBackBarButtonItem:nil]; // set as nil

[self.navigationItem setLeftBarButtonItem:nil animated:NO];  // left bar item as nil