UISplitViewController 是否必须是 iPad 应用程序的根控制器?

发布于 2024-08-22 07:22:11 字数 323 浏览 6 评论 0原文

根据 Apple 关于 UISplitViewController 的文档(在新的 iPad 3.2 SDK 中),看起来他们只打算将其用作应用程序的根控制器。换句话说......看起来你不能将 UISplitViewController 推到 UINavigationController 上,因为显然 UINavigationController 需要保存分割视图。

任何人都可以确认这是否是 UISplitViewController 的真正限制?我希望在我的应用程序中在 UINavigationController 层次结构深处使用分割视图,但看起来我无法做到这一点,除非有办法。

谢谢你!

According to Apple's documentation on the UISplitViewController (in the new iPad 3.2 SDK) it looks like they intend for you to use it only as a root controller of an app. In other words...it seams like you cannot push a UISplitViewController onto a UINavigationController because obviously the UINavigationController would need to hold the split view.

Can anyone confirm if this is a true limitation of the UISplitViewController? I was hoping to use the split view in my app a few levels deep in my UINavigationController hierarchy but it looks like I won't be able to do that unless there is a way.

Thank you!

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

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

发布评论

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

评论(5

一笔一画续写前缘 2024-08-29 07:22:11

每当我尝试以模态方式呈现 UISplitViewController 时,我的应用程序就会崩溃。

My app crashes whenever I try to present a UISplitViewController modally.

哭泣的笑容 2024-08-29 07:22:11

这是一篇旧文章,但我发现它有助于我以不同的方式思考,这就是我解决问题的方法。

我以编程方式创建了我的 splitViewController 。然后我用一个数字标记它,并将其作为子视图添加到我当前的视图中。


FirstViewController* firstView = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];    
SecondViewController* secondView = [[[SecondViewController alloc]  initWithNibName:@"SecondViewController" bundle:nil] autorelease];        
UISplitViewController* splitVC = [[UISplitViewController alloc] init];
[splitVC setDelegate:secondView];    
splitVC.viewControllers = [NSArray arrayWithObjects:firstView, secondView, nil];    
splitVC.view.tag = 99;    
[self.view addSubview:splitVC.view];

之后,将显示 splitView,但为了摆脱它,我必须将其从视图中删除,因此我在 viewcontrollers 之间创建了一个通知。在主视图控制器中我添加了观察者。 (注意:主视图控制器不是 splitViewController 或其视图之一,它是加载 splitViewController 的视图控制器)

NSNotificationCenter *splitViewObserver = [NSNotificationCenter defaultCenter];
[splitViewObserver addObserver:self selector:@selector(removeSplitView) name:@"removeSplitView" object:nil];

在选择器“removeSplitView< /code>" 我将当前视图的所有子视图放入 for 循环中,并搜索带有标签 99 的 UIView 类对象并将其从超级视图中删除。

NSArray *subviews = [self.view subviews];

for (int i = 0; i < [subviews count]; i++) {
    if ([[subviews objectAtIndex:i] isKindOfClass:[UIView class]]) {
        UIView *tempView = [subviews objectAtIndex:i];
        if (tempView.tag == 99) {
            [[subviews objectAtIndex:i] removeFromSuperview];
        }
    }
}

在第一个View中,我有一个名为done的方法,它发布主ViewController正在观察的通知。

-(IBAction) done:(id)sender {       
    [fileSelectedNotification postNotificationName:@"removeSplitView" object:self];    
}

您还必须在应用中的某个位置创建 fileSelectedNotification。我通过 viewDidLoad 做到了这一点。看起来像这样。

fileSelectedNotification = [NSNotificationCenter defaultCenter];

当然,我也将其添加

NSNotiicationCenter *filesSelectedNotification;

到此 viewController 的 .h 文件中。

因此,当我按下“完成”按钮(这是我的应用程序上的一个栏按钮)时,它会从视图中删除 splitViewController

工作正常。我只是通过阅读文档得到了这一切。

This is an old post, but i found it useful to help me think in a different way, and this is how i solved the problem.

I created my splitViewController programmatically. I then tagged it with a number, and just added it as a subview to my current view.


FirstViewController* firstView = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];    
SecondViewController* secondView = [[[SecondViewController alloc]  initWithNibName:@"SecondViewController" bundle:nil] autorelease];        
UISplitViewController* splitVC = [[UISplitViewController alloc] init];
[splitVC setDelegate:secondView];    
splitVC.viewControllers = [NSArray arrayWithObjects:firstView, secondView, nil];    
splitVC.view.tag = 99;    
[self.view addSubview:splitVC.view];

After that, splitView is displayed, but to get rid of it, i have to remove it from the view, so i created a notification between the viewcontrollers. In the main view controller I added the observer. (note: the main view controller isn't the splitViewController or one of it's views, it's the view controller that loads the splitViewController)

NSNotificationCenter *splitViewObserver = [NSNotificationCenter defaultCenter];
[splitViewObserver addObserver:self selector:@selector(removeSplitView) name:@"removeSplitView" object:nil];

in the selector "removeSplitView" i put all of the subviews of my current view through a for loop and search for a UIView class object with the tag 99 and remove it from the superview.

NSArray *subviews = [self.view subviews];

for (int i = 0; i < [subviews count]; i++) {
    if ([[subviews objectAtIndex:i] isKindOfClass:[UIView class]]) {
        UIView *tempView = [subviews objectAtIndex:i];
        if (tempView.tag == 99) {
            [[subviews objectAtIndex:i] removeFromSuperview];
        }
    }
}

In the firstView I have a method called done that posts the notification that the main ViewController is observing.

-(IBAction) done:(id)sender {       
    [fileSelectedNotification postNotificationName:@"removeSplitView" object:self];    
}

You'll also have to create the fileSelectedNotification somewhere in your app. I did this via viewDidLoad. It looks like this.

fileSelectedNotification = [NSNotificationCenter defaultCenter];

I of course also added this

NSNotiicationCenter *filesSelectedNotification;

to the .h file of this viewController.

Thus, when I push the done button (which is a bar button on my app) it removes the splitViewController from view.

Works fine. I got all this just from reading docs.

微暖i 2024-08-29 07:22:11

Apple HIG 说你不能。意味着他们可能阻止你这样做,所以我怀疑你能否让它发挥作用。一些开发者已经编写了自己的

Apple HIG says you can't. Means they've probably blocked you from doing it, so I doubt you'll get it working. some devs have written their own

瑾夏年华 2024-08-29 07:22:11

一点也不。例如,可以在层次结构的根部有一个选项卡栏控制器,其中每个选项卡都有一个分割视图控制器。

请参阅我关于将拆分视图控制器改造为选项卡栏界面的文章: http: //markivsblog.blogspot.com/2010/04/retrofitting-ipad-uisplitviewcontroller.html

Not at all. It is possible to have a tab bar controller at the root of the hierarchy, where each tab has a split view controller, for example.

See my post about retrofitting split view controllers to a tab bar interface: http://markivsblog.blogspot.com/2010/04/retrofitting-ipad-uisplitviewcontroller.html

飘落散花 2024-08-29 07:22:11

仅供参考,我认为这是要走的路:请参阅类似的问题

Just for reference, I think this is the way to go: See this similar question.

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