View Full Version : editButtonItem in a segmented control?
John Baughman
Oct 17, 2009, 07:29 AM
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
dejo
Oct 17, 2009, 02:28 PM
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?
Yes, it's possible, via the customView property of UIBarButtonItem. Check the NavBar (http://developer.apple.com/iphone/library/samplecode/NavBar/index.html) sample app for how you might do this.
John Baughman
Oct 17, 2009, 09:29 PM
Yes, it's possible, via the customView property of UIBarButtonItem. Check the NavBar (http://developer.apple.com/iphone/library/samplecode/NavBar/index.html) sample app for how you might do this.
I have successfully created a 2 button segmented control like this...
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
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.