简体   繁体   English

UISplitViewController多个详细信息视图分段控件

[英]UISplitViewController Multiple Detail Views Segmented Control

I'm working on an iPad app in a split view controller where the app will remain in landscape the entire time. 我正在使用拆分视图控制器中的iPad应用程序,该应用程序将始终保持横向。 I would like the root view controller to remain a list and the detail view controller to swap out 4 different views controlled by a UISegmentedControl. 我希望根视图控制器保留列表,而细节视图控制器交换出由UISegmentedControl控制的4个不同视图。

I'm following this post here UISegmentedControl Best Practice , however when I swap in my view controllers, they don't properly fit in the detailview controller, they are cut off as if they are trying to draw for ipad portrait orientation. 我在这里遵循UISegmentedControl最佳实践的文章 ,但是当我交换视图控制器时,它们不能正确地插入到detailview控制器中,它们会被切断,就好像它们试图为ipad纵向方向绘制一样。

If I completely ignore the segmented control approach and have a detail view, the view size properly in the detail view, but once i try to swap them in with a segmented control is where I run into trouble. 如果我完全忽略了分段控件的方法并拥有详细视图,则在详细视图中视图的大小会正确,但是一旦我尝试将其与分段控件交换,就会遇到麻烦。

Is there a way to tell the swapped in views to draw correctly? 有没有办法告诉交换的视图正确绘制?

Have you tried: 你有没有尝试过:

swappedInView.frame = detailController.view.bounds;

when you call 你打电话时

[detailedController.view addSubview:swappedInView];

?

Their contents need to have their resizing behaviors (most easily in xcode/IB) set appropriately. 它们的内容需要适当地设置其调整大小的行为(在xcode / IB中最容易实现)。

I am using a UISegmentControl as well, but adding my views programmatically. 我也使用UISegmentControl,但是以编程方式添加了我的视图。 I have my default view (segment 0) loaded first in the viewDidLoad of the rootController. 我将我的默认视图(段0)首先加载到rootController的viewDidLoad中。 Then based on which segment is pressed, I check if the view has been initialized, if not, initialize, then add it as a subview. 然后根据按下的段,检查视图是否已初始化,如果未初始化,则将其添加为子视图。 Then remove the other view. 然后删除另一个视图。 I had a similar post on this on how to keep track of it that might help you out, and has the code from Beginning iPhone 4 Development book that I used for my own app. 我在这方面也有一篇类似的文章,介绍如何跟踪它可能对您有帮助,并提供了我自己的应用程序使用的《 Beginning iPhone 4 Development》一书中的代码。 Here's the code snippet to get you started if you want to go this approach: 如果您想采用这种方法,请参考以下代码片段:

if (self.yellowViewController.view.superview == nil)
{
    if (self.yellowViewController == nil)
    {
        YellowViewController *yellowController =
        [[YellowViewController alloc] initWithNibName:@"YellowView"
bundle:nil];
        self.yellowViewController = yellowController;
        [yellowController release];
    }
    [blueViewController.view removeFromSuperview];
    [self.view insertSubview:yellowViewController.view atIndex:0];
}
else
{
    if (self.blueViewController == nil)
    {
        BlueViewController *blueController =
        [[BlueViewController alloc] initWithNibName:@"BlueView"
bundle:nil];
        self.blueViewController = blueController;
        [blueController release];
    }
    [yellowViewController.view removeFromSuperview];
    [self.view insertSubview:blueViewController.view atIndex:0];
}

In my own, I add as a subview, instead of inserting it behind the other views (they had a toolbar in the front in their example). 在我自己的视图中,我添加为子视图,而不是将其插入其他视图的后面(在示例的前面,它们有一个工具栏)。 So if say segment 3 was pressed, then I would check the other views if their superviews were present, remove that view, add my view. 因此,如果说第3段被按下,那么我将检查其他视图是否存在其超级视图,删除该视图,添加我的视图。 Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM