I have a UIViewController class with a navigation bar shown and a button on the rightmost end of the navigation bar. Then right underneath it is my main content area with a UISegmentedControl shown below the navigation bar.
Whenever I click/tap on the navigation bar near the right button but not directly on the button, I am getting an unexpected button press event. Usually, it's when I'm trying tap on the right most segment item that happens to be placed beneath the button. So the tap is on the button instead of the segment. How do I make sure the event is directed to the right receiver?
My UI is created with Interface Builder and the UISegmentedControl is hooked up to my class in the nib file.
My class:
@interface MyViewController : UIViewController
{
IBOutlet UISegmentedControl *segmentedControl;
}
@end
@implementation MyViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self action:@selector(onButtonPressed:)];
self.navigationItem.rightBarButtonItem = button;
[button release];
}
- (IBAction)onButtonPressed:(id)sender
{
NSLog(@"onButtonPressed reached!");
}
- (IBAction)onSegmentItemPressed:(id)sender
{
NSLog(@"onSegmentItemPressed for: %d", [segmentedControl selectedSegmentIndex]);
}
@end