UIPopover: UISegmentedControl вместо заголовка - PullRequest
1 голос
/ 15 ноября 2011

У меня есть Popover и заголовок @ "Заголовок".Возможно ли иметь там UISegmentedControl вместо заголовка?Другими словами, я хочу всплывающее окно с сегментированным управлением в середине заголовка.Как?

Содержимое popover - это UITableViewController, оно находится внутри UINavigationController, и я представляю его через presentPopoverFromBarButtonItem:.

Ответы [ 2 ]

0 голосов
/ 15 ноября 2011
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;
0 голосов
/ 15 ноября 2011

Используйте 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]];
...