如何将 UISegmentControl 置于 UIPopoverController 顶部工具栏中的中心

发布于 2024-11-27 14:56:22 字数 2059 浏览 2 评论 0原文

我看过一些关于此的不同帖子,但我似乎无法让它发挥作用。我基本上有一个 UITableView 并希望在弹出控制器顶部进行排序按钮。我按照这篇文章:顶部的 UIPopoverController 工具栏开始。在我的控制器(即 navigationController 的 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;

另外,如果我想在工具栏中的弹出窗口控制器底部显示数据,我不知道在哪里执行此操作。按照相同的示例:顶部的UIPopoverController工具栏,我想在我的navigationController中,我会做一些事情像这样:

 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];

当我尝试这个时,我看到一个工具栏上什么也没有,它的色调比弹出窗口的其余部分更浅。

总而言之,我不确定在哪里为具有导航控制器的弹出窗口初始化工具栏或栏按钮项,如示例中所示。我也不确定如何集中数据。谢谢。

I've seen a few different posts on this, but I can't seem to get it working. I basically have a UITableView and want sort buttons at the top of a popover controller. I followed this post: UIPopoverController toolbar at top in order to get started. In my controller that is the rootViewController of the navigationController, I can create a UISegmentControl and place it at the top. However, it does not look like the picture in that it's not centered. Maybe because the way I get it into the popover is in the viewDidLoad of the popover like this:

   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;

Also, if I want to present data at the bottom of the popovercontroller in a toolbar, I'm not sure where to do that. Following the same example: UIPopoverController toolbar at top, I thought in my navigationController, I would do something like this:

 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];

When I try this, I see a toolBar with nothing in it, that is a lighter tint than the rest of the popover.

To summarize, I'm not sure as to where you would initialize toolbar or barbuttonitems for a popover that has a navigationcontroller like in the example. I'm also not sure how to center the data. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菊凝晚露 2024-12-04 14:56:22

只需将 UISegmentedControl 设置为根视图控制器的 navigationItemtitleView ,您可能会最适合。

You’ll probably be best suited by just setting your UISegmentedControl as the titleView of your root view controller’s navigationItem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文