Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

John Baughman

macrumors regular
Original poster
Oct 27, 2003
100
0
Using...

self.navigationItem.leftBarButtonItem = self.editButtonItem;

I have an edit button in my navigation bar that works great but I would like to put it in a segmented control with an Add button. Is this possible?

As far as I can tell, the answer is no.

Thanks,

John
 

John Baughman

macrumors regular
Original poster
Oct 27, 2003
100
0
Yes, it's possible, via the customView property of UIBarButtonItem. Check the NavBar sample app for how you might do this.

I have successfully created a 2 button segmented control like this...

Code:
segmentedControl = [ [ UISegmentedControl alloc ] initWithItems: nil ]; 
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; 
[ segmentedControl insertSegmentWithTitle: @"Prefs" atIndex: 0 
										 animated: NO ]; 
[ segmentedControl insertSegmentWithTitle: @"Add" atIndex: 1 
										 animated: NO ]; 
		
[ segmentedControl addTarget: self action: @selector(segmentedControlPressed:) 
		forControlEvents:UIControlEventValueChanged ];
		
UIBarButtonItem *segmentItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];

self.navigationItem.rightBarButtonItem = segmentItem;

[segmentedControl release];
[segmentItem release];

What I want to do is replace the Pref button at index 0 with an Edit button created with self.editButtonItem, ie with all the default behavior of an Edit button. The only way I can find to add items to the segment is with title, image, or items (array with images or titles).

John
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.