具有多个视图控制器的 PopoverController 中的 UISegmentedControl

发布于 2024-12-11 21:08:02 字数 429 浏览 0 评论 0原文

我希望将 UISegmentedControl 嵌入到 PopoverController 中,类似于此问题中所描述的内容: UISegmentedControl 嵌入 UINavigationBar/Item

不同之处在于,我想在 UINavigationBar/Item 中显示的每个视图都有一个不同的视图控制器弹出窗口,具体取决于分段控件上选定的索引。我不确定我会如何去做这件事。每当我尝试将新视图推送到根视图控制器顶部时,UISegmentedControl 就会消失。我只想在两个视图控制器之间切换,同时保持 UISegmentedControl 可见。这可能吗?

提前致谢!

I would like to have a UISegmentedControl embedded in a PopoverController, similar to what is described in this SO question : UISegmentedControl embedded in a UINavigationBar/Item

The difference is that I have a different view controller for each view that I want to show in the popover, depending on the selected index on the Segmented Control. I'm not sure how I would go about doing this. Whenever I try to push a new view on top of the root view controller, the UISegmentedControl disappears. I would just like to switch between the two viewcontrollers, while keeping the UISegmentedControl visible. Is this even possible?

Thanks in advance!

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

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

发布评论

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

评论(2

温柔戏命师 2024-12-18 21:08:02

如果segmentBar上的每个段都有不同的viewController,则必须使用容器viewController,将每个viewController的视图添加为自身的子视图,或者将其视图设置为viewController的视图的视图。例如:

UIViewController* containerController = [[[UIViewController alloc] init] autorelease];


//Inside the viewDidLoad of the the ContainerController class, do the following:

//Initialize all three viewControllers
UIViewController* test1 = [[[UIViewController alloc] init] autorelease];
UIViewController* test1 = [[[UIViewController alloc] init] autorelease];
UIViewController* test1 = [[[UIViewController alloc] init] autorelease];

//set up the segment and add it to the container's navBar's title view.
[segmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];


- (void)segmentValueChanged:(id)sender 
{

    //if first tab selected
    [self.view removeAllSubviews];
    [self.view addSubview:test1.view];

    //if second tab selected
    [self.view removeAllSubviews];
    [self.view addSubview:test2.view];

    //if third tab selected
    [self.view removeAllSubviews];
    [self.view addSubview:test3.view];

}

您可以只设置 self.view = test1.view,而不是将其添加为子视图。显然,您将使用容器视图来初始化 navController 并将该 navController 放入弹出窗口中。希望这有帮助!

If its a different viewController for each one of the segments on the segmentBar, you'll have to use a container viewController that adds the views of each of the viewController as a subview on itself or sets its view to that of the viewController's view. For example:

UIViewController* containerController = [[[UIViewController alloc] init] autorelease];


//Inside the viewDidLoad of the the ContainerController class, do the following:

//Initialize all three viewControllers
UIViewController* test1 = [[[UIViewController alloc] init] autorelease];
UIViewController* test1 = [[[UIViewController alloc] init] autorelease];
UIViewController* test1 = [[[UIViewController alloc] init] autorelease];

//set up the segment and add it to the container's navBar's title view.
[segmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];


- (void)segmentValueChanged:(id)sender 
{

    //if first tab selected
    [self.view removeAllSubviews];
    [self.view addSubview:test1.view];

    //if second tab selected
    [self.view removeAllSubviews];
    [self.view addSubview:test2.view];

    //if third tab selected
    [self.view removeAllSubviews];
    [self.view addSubview:test3.view];

}

Instead of adding it as a subView, you might be able to just set self.view = test1.view. Obviously, you would use the container view to initialize the navController and put that navController inside the popover. Hope this helps!

铃予 2024-12-18 21:08:02

如果您使用presentModalViewController方法在屏幕上显示新的视图控制器,它将始终覆盖整个屏幕及其下方的内容。这就是它的工作原理。

根据文档:

在iPhone和iPod touch设备上,modalViewController的视图是
始终全屏呈现。在 iPad 上,演示文稿取决于
modalPresentationStyle 属性中的值。

做到这一点并且仍然能够控制视图控制器如何定位的方法是创建您自己的演示方法。

If you are using presentModalViewController method to show your new view controller on the screen, it will always cover the entire screen and what ever is underneath it. That's just how it works.

As per docs:

On iPhone and iPod touch devices, the view of modalViewController is
always presented full screen. On iPad, the presentation depends on the
value in the modalPresentationStyle property.

The way to do it and still being able to control how the view controller is positioned is to create your own presentation method.

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