I have a UIImageView, which I am adding as the background of a UIBarButtonItem. I make the UIBarButtonItem as the right barbuttonitem of my navigation controller. I am not able to handle the UIBarButtonItem click event as the control doesn’t enter the method, while I am debugging. What could be the reason for this?
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,32,32)];
[myImage setImage:[UIImage imageNamed:@"logo.png"]];
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:myImage];
//rightBarButton.target = self;
//rightBarButton.action = @selector(onMyMethod);
if(isRight){
self.navigationItem.rightBarButtonItem = rightBarButton;
self.navigationItem.rightBarButtonItem.target = self;
self.navigationItem.rightBarButtonItem.action = @selector(onMyMethod);
}
Going by RIP’s answer, I changed the
UIBarButtonItemand created aUIButtoninstead and added it as subview of the navigationcontroller