My code:
-(void)loadView {
[super loadView];
self.informationButton = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = self.informationButton;
self.informationButton.target = self;
self.informationButton.action = @selector(showHelpInfo);
}
-(void)showHelpInfo {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test"
message:@"Test"
delegate:nil
cancelButtonTitle:@"cansel"
otherButtonTitles:nil, nil];
[alert show];
}
Then I clicking on my informationButton uialertview not shows. There is my error?
Your UIButton is the thing that now dispatches actions and events because the UIBarButtonItem is merely a container for it at this point. So, when you click that button, it’s the UIButton that’s intercepting the touch event. Simply make a UIButton object that has the same action your UIBarButtonItem.