【发布时间】:2011-08-01 18:36:44
【问题描述】:
我已经看到了一些不同的帖子,但我似乎无法让它发挥作用。我基本上有一个 UITableView 并且想要在弹出控制器顶部的排序按钮。我关注了这篇文章:UIPopoverController toolbar at top 以便开始。在作为导航控制器的 rootViewController 的控制器中,我可以创建一个 UISegmentControl 并将其放在顶部。但是,它看起来不像图片,因为它没有居中。也许是因为我将它放入弹出框的方式是在弹出框的 viewDidLoad 中,如下所示:
UISegmentedControl *topSegmentControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"One", @"Two", @"Three", @"Four", nil]];
topSegmentControl.backgroundColor = [UIColor clearColor];
topSegmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
UIBarButtonItem *toolBarCustom = [[UIBarButtonItem alloc] initWithCustomView:topSegmentControl];
// UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
self.navigationItem.leftBarButtonItem = toolBarCustom;
另外,如果我想在工具栏中的 popovercontroller 底部显示数据,我不知道在哪里做。按照同样的例子:UIPopoverController toolbar at top,我想在我的导航控制器中,我会做这样的事情:
UISegmentedControl *topSegmentControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"BottomOne", @"BottomTwo", @"BottomThree", nil]];
// topSegmentControl.backgroundColor = [UIColor clearColor];
topSegmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
UIBarButtonItem *toolBarCustom = [[UIBarButtonItem alloc] initWithCustomView:topSegmentControl];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *array = [NSArray arrayWithObjects:spaceItem, toolBarCustom, spaceItem, nil];
[navController setToolbarItems:toolBarCustom];
[navController setToolbarHidden:NO];
当我尝试这个时,我看到一个工具栏没有任何内容,它比弹出框的其余部分颜色更浅。
总而言之,我不确定您将在哪里初始化工具栏或 barbuttonitems 以用于具有示例中导航控制器的弹出框。我也不确定如何使数据居中。谢谢。
【问题讨论】:
标签: iphone uinavigationcontroller uipopovercontroller uibarbuttonitem uitoolbar