I tried to disable the back back butt开发者_Go百科on item of the nav controller with:
self.navigationItem.backBarButtonItem.enabled = NO;
It doesn't seem to work on the backButtonItem, but works on other bar button items. Is there a way to disable it temporarily without having to hide it?
You should use the following instead:
self.navigationItem.hidesBackButton = YES;
Hopefully this should work.
In my case I didn't want the back button completely hidden, I just wanted it very briefly disabled while my initialization routine was finishing. So here's what I ended up doing:
// in initWithNibName
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[backButton setTitle:@"Cancel" forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[backButton.titleLabel setFont:[UIFont boldSystemFontOfSize:13.0f]];
[backButton setFrame:CGRectMake(0.0f, 0.0f, 68.0f, 28.0f)];
[backButton setEnabled:NO];
[backButton addTarget:self action:@selector(tappedClose) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = buttonItem;
[buttonItem release];
and then later on, after the initialization routine is finished, I do:
UIButton *backNavigationButton = (UIButton *)self.navigationItem.leftBarButtonItem.customView;
[backNavigationButton setEnabled:YES];
also later on I plan on changing from using UIButtonTypeRoundedRect
to UIButtonTypeCustom
and supplying my own "back-button-esque" button images. Hope this helps!
精彩评论