我有一个Popover和标题@“Title”。是否可以在那里使用UISegmentedControl,而不是标题?换句话说,我想要一个在标题中间有分段控件的popover。怎么样?
popover的内容是UITableViewController,它在UINavigationController中,我通过presentPopoverFromBarButtonItem呈现它:。
答案 0 :(得分:0)
使用弹出窗口顶部的UIToolbar
。无论是在界面构建器中,还是以编程方式,插入UISegmentedControl
,在其两侧都有灵活的空间。例如:
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems
[NSArray arrayWithObjects:@"Segment 1", @"Segment 2", nil]];
UIBarButtonItem *segmentedBarButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[self.toolbar setItems:[NSArray arrayWithObjects:flexibleSpace, segmentedBarButton, flexibleSpace]];
答案 1 :(得分:0)
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;