Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we disabled the navigation controller of leftBarButtonItem that is back button of the view controller in iPhone?

I want to disabled the default back button of navigation controller

self.navigationItem.rightBarButtonItem.enabled = NO; 
// Below code does not work since leftBarButtonItem is always nil.
self.navigationItem.leftBarButtonItem.enabled = NO;

I have done it with manually shown below, But Is there any property to disabled the default back button with just single line?

backButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 100, 30)];
[backButton setBackgroundImage:[UIImage imageNamed:@"backbutton_100.png"] forState:UIControlStateNormal];
[backButton addTarget:self  action:@selector(backAction:)  forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:@"  All Customers" forState:UIControlStateNormal];
backButton.titleLabel.font = [UIFont boldSystemFontOfSize:12];
[buttonView addSubview:backButton];

UIBarButtonItem* leftButton = [[UIBarButtonItem alloc] initWithCustomView:buttonView];
self.navigationItem.leftBarButtonItem = leftButton;
[leftButton release];

// Now it is working.
self.navigationItem.leftBarButtonItem.enabled = NO;
like image 259
Madan Mohan Avatar asked Jul 08 '10 08:07

Madan Mohan


People also ask

How do I disable the Back button on my Iphone?

Yes, the back button can be disabled. Please navigate to Advanced Website Kiosk Settings–>Navigation–>Disable back button. Kindly enable this restriction to disallow the usage of the back button on the iOS device.

How do I hide the navigation back button in Swift 4?

Go to attributes inspector and uncheck show Navigation Bar to hide back button.


1 Answers

Its very easy ..... just try this out

self.navigationController.navigationBar.userInteractionEnabled = NO;   //for  disabling 

self.navigationController.navigationBar.userInteractionEnabled = YES; //for again enabling
like image 172
vivek Avatar answered Oct 13 '22 01:10

vivek