Search code examples
iosuipopover

UIPopover: UISegmentedControl instead of title


I have a Popover and the title @"Title". Is it possible to have UISegmentedControl there, instead of the title? In other words, I want a popover which has a segmentedcontrol in the middle of header. How to?

The content of popover is UITableViewController, it is inside a UINavigationController, and I present it via presentPopoverFromBarButtonItem:.


Solution

  • UISegmentedControl *sc = [[[UISegmentedControl alloc] initWithItems:nil] autorelease];
    // config the control
    
    UIBarButtonItem *scItem = [[[UIBarButtonItem alloc] initWithCustomView:sc] autorelease];
    
    // add the segmented control, instead of the UILabel title
    self.navigationItem.titleView = scItem.customView;