1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

editButtonItem in a segmented control?

Discussion in 'iPhone/iPad Programming' started by John Baughman, Oct 17, 2009.

  1. macrumors member


    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.


  2. Moderator


    Staff Member

    Yes, it's possible, via the customView property of UIBarButtonItem. Check the NavBar sample app for how you might do this.
  3. macrumors member

    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).


Share This Page