I want two rightBarButtonItem's on my UINavigationBar. How can I accomplish this?
+1
A:
You can use a UISegmentedControl with two buttons and configure it with the momentary
property set to YES.
This is what is used in the Mail application to go to next/previous message.
Update
In order to assign the UISegmentedControl]1 as a right button, you have to wrap it inside a UIBarButtonItem (sample code taken from the NavBar sample application):
- (void)viewDidLoad
{
// "Segmented" control to the right
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@"up.png"],
[UIImage imageNamed:@"down.png"],
nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 90, kCustomButtonHeight);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
}
Laurent Etiemble
2010-06-09 18:03:23
Can a UISegmentedControl be casted as UIBarButtonItem?
Sheehan Alam
2010-06-10 02:05:15
I have update my answer to show how to use an UISegmentedControl as rightBarButtonItem.
Laurent Etiemble
2010-06-10 07:09:39