从笔尖加载/初始化辅助 UITabBarController

发布于 2024-10-26 20:36:43 字数 965 浏览 0 评论 0原文

在我尝试开发的应用程序中,我将 UINavigationController 作为根控制器。我使用非常常见的代码初始化视图:

MySubclassOfViewController *vc = [[MySubclassOfViewController alloc]
                                  initWithNibName:@"MySubclassOfViewController"
                                  bundle:nil];
vc.title = @"A title";
[self.navigationController pushViewController:vc animated:YES];
[vc release];

在一系列视图之后,我想加载 UITabBarController。

  1. 有没有一种方法可以像上面一样以相同的方式设计 nib 文件并创建 UITabBarController 的实例?
    我知道我可以通过编程方式或通过显式声明一个插座并将其与笔尖中的控制器连接来完成此操作。也可以使用类似的方法来初始化控制器

    NSArray *objects = [[NSBundle mainBundle]
                         loadNibNamed:@“MySubclassOfViewController”
                         所有者:自己
                         选项:无];
    self = [对象objectAtIndex:0];
    [对象释放];
    

    但是我可以不用额外的工作就能做到吗?打字?

  2. 假设我定义了 UITabBarConroller 的子类(尽管我知道 Apple 文档中不鼓励这样做,但只是出于好奇)。当我创建子类的实例时,我可以以某种方式从笔尖加载超类部分吗?

In the application I'm trying to develop I have UINavigationController as a root controller. I initialize views using pretty common code:

MySubclassOfViewController *vc = [[MySubclassOfViewController alloc]
                                  initWithNibName:@"MySubclassOfViewController"
                                  bundle:nil];
vc.title = @"A title";
[self.navigationController pushViewController:vc animated:YES];
[vc release];

After a succession of some views I want to load UITabBarController.

  1. Is there a way to desing the nib file and create an instance of UITabBarController the same way as above?
    I know I can do this programmatically or by explicitly declaring an outlet and connecting it with the controller in the nib. It's also possible to initialize the controller using something like

    NSArray *objects = [[NSBundle mainBundle]
                         loadNibNamed:@"MySubclassOfViewController"
                         owner:self
                         options:nil];
    self = [objects objectAtIndex:0];
    [objects release];
    

    But can I make it without extra work & typing?

  2. Let's say I define a subclass of UITabBarConroller (although I know it's discouraged in the Apple docs, but just out of curiosity). When I make an instance of the subclass, can I somehow load the superclass part out of a nib?

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

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

发布评论

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

评论(1

青衫负雪 2024-11-02 20:36:43

我自己解决了我的问题。经过一番研究,我得出了这些结论。

  1. 不可能以同样的方式做到这一点(即UITabBarController *tbc = [[UITabBarController alloc] initWithNib...)要么应该有一个额外的控制器插座,或者控制器应该显式alloc/init'ed(但不是initWithNibName),或者可以使用loadNibNamed实例化代码>. 就是这样。原因是标签栏控制器没有声明将它们连接到子视图控制器的出口。 (有关加载笔尖的更多详细信息,请查看开发混沌理论博客)。
  2. 如果前面的答案是“是”,那么我所要做的就是将 Interface Builder 中的自定义类设置为我的子类。这适用于其他对象(好吧,可能除了 UINavigationController,它也不适合子类化)。但由于标签栏控制器的“简单”初始化是不可能的,所以这也是不可能的。

对此有何评论? :)

I've solved my problem myself. After some research, I came to these conclusions.

  1. It's not possible to do it the same way (i.e. UITabBarController *tbc = [[UITabBarController alloc] initWithNib...) Either there should be an extra outlet for the controller, or the controller should be explicitly alloc/init'ed (but not initWithNibName), or it could be instantiated using loadNibNamed. That's it. The reason for this is that the tab bar controller doesn't have outlets declared to connect them to children view controller. (For more details on loading nibs check Development Chaos Theory blog).
  2. If the previous answer was 'yes', then all I had to do was to set the custom class in the Interface Builder to my subclass. This works for other objects (well, may be except the UINavigationController, which is not intended for subclassing as well). But since the 'simple' initialization of a tab bar controller is impossible, this is impossible too.

Any comments on this? :)

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