For my back buttons in the navigation controller, I wanted to use a custom image, so I figured that creating a custom button with an image and placing it inside a UIBarButtonItem would do the trick.
It works fine, but at random times while pressing the button, the image goes shady (like it's being pressed) and stays that way, while nothing happens (the action is not being called)! If I press the button again, it will perform the action just fine. This doesn't happen always, which is the reason why I am having a hard time debugging it.
Also, it happens only when I create custom buttons and place them on the left navigation item (where the default back button item should be). It never happens on the navigation item.
Any thoughts?
Code:
UIImage* buttonImage = [UIImage imageNamed: @"header.navigation.back.png"];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
aButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width/2, 32);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:@selector(backToPriorView) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = backButton;
[backButton release];
It works fine, but at random times while pressing the button, the image goes shady (like it's being pressed) and stays that way, while nothing happens (the action is not being called)! If I press the button again, it will perform the action just fine. This doesn't happen always, which is the reason why I am having a hard time debugging it.
Also, it happens only when I create custom buttons and place them on the left navigation item (where the default back button item should be). It never happens on the navigation item.
Any thoughts?