如何手动创建UISplitView? [英] How do I create a UISplitView manually?

查看:104
本文介绍了如何手动创建UISplitView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序将导航到UISplitView(完全在另一个视图中),如下所示:

I have an app that is going to navigate to a UISplitView (inside another view altogether) like so:

- (void) switchToMyDayView {
    NSLog(@"Show My Day Screen");

    if (self.myDayController.view.superview == nil) {
        if (self.myDayController == nil) {
            MyDayController *myController = [[MyDayController alloc] initWithNibName:@"MyDay" bundle:nil];
            self.myDayController = myController;
            [myController release];
        }

        [homeScreenController.view removeFromSuperview];
        [self.view insertSubview:self.myDayController.view atIndex:0];
    }
}

这是在主导航界面上完成的

Which is done on the main navigation screen

现在,MyDayController有一个名为MyDay.xib的XIB,它包含以下项目:

Now, the MyDayController has a XIB called MyDay.xib which has these items:


文件所有者:MyDayController

File's Owner: MyDayController

第一响应者:UIResponder

First Responder: UIResponder

拆分视图控制器

 ---->Navigation Controller

         ---->Navigation Bar

         ----> Table View Controller

                 ----> Navigation Item

 ---->View Controller


所以,我需要一些更多的组件,我需要一个UITableViewController和一个UISplitViewControllerDelegate正确吗?

So, I need some more components here, I need a UITableViewController and a UISplitViewControllerDelegate correct?

我打算在我的MyDayController中实现这些协议,是这种标准吗?

I was going to just implement these protocols in my MyDayController, is this sort of standard?

因此,在上面的代码之后,我收到一个错误:

So, after the code above, I get an error:

- [ UIViewController _loadViewFromNibNamed:bundle:]加载了MyDay笔尖,但未设置视图插座。

-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MyDay" nib but the view outlet was not set.

所以,如何使用UISplitViewController修复它?我知道UISplitViewController有一个view属性,但我不能用它/在IB中连接它可以吗?

so, how can I fix it using the UISplitViewController? I know that the UISplitViewController has a view property, but I cannot use it/connect it up in IB can I?

非常感谢

标记

推荐答案

您不应该继承UISplitViewController的子类。您的MyDayController课程中有什么行为? UISplitViewController基本上只是处理为您设置主视图和详细视图,因此您的责任是实现这些控制器。

You shouldn't have to subclass UISplitViewController. What behavior is in your "MyDayController" class? UISplitViewController basically just handles laying out the master and detail views for you, so your responsibility is to implement those controllers.

如果拆分视图位于应用程序的顶层,您可以将其添加到应用程序的主窗口笔尖。如果不是,只需以编程方式创建它:

If the split view is at the top level of your app, you can add it to your app's main window nib. If it isn't, just create it programatically:

- (void) switchToMyDayView {
    NSLog(@"Show My Day Screen");

    if (self.myDayController == nil) {
        YourMasterViewController *masterViewController = [[YourMasterViewController alloc] initWithNibName:@"MasterView" bundle:nil];
        YourDetailViewController *detailViewController = [[YourDetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
        UISplitViewController *myController = [[UISplitViewController alloc] init;
        myController.viewControllers = [NSArray arrayWithObjects:masterViewController, detailViewController, nil];
        [masterViewController release];
        [detailViewController release];

        self.myDayController = myController;
        [myController release];         
    }

    [homeScreenController.view removeFromSuperview];
    [self.view insertSubview:self.myDayController.view atIndex:0];
}

你也不需要自测试.myDayController.view.superview == nil 因为它隐含在 self.myDayController == nil

You also don't need the test for self.myDayController.view.superview == nil as it's implicit in self.myDayController == nil

这篇关于如何手动创建UISplitView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆