从笔尖加载/初始化辅助 UITabBarController
在我尝试开发的应用程序中,我将 UINavigationController 作为根控制器。我使用非常常见的代码初始化视图:
MySubclassOfViewController *vc = [[MySubclassOfViewController alloc]
initWithNibName:@"MySubclassOfViewController"
bundle:nil];
vc.title = @"A title";
[self.navigationController pushViewController:vc animated:YES];
[vc release];
在一系列视图之后,我想加载 UITabBarController。
有没有一种方法可以像上面一样以相同的方式设计 nib 文件并创建 UITabBarController 的实例?
我知道我可以通过编程方式或通过显式声明一个插座并将其与笔尖中的控制器连接来完成此操作。也可以使用类似的方法来初始化控制器NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@“MySubclassOfViewController” 所有者:自己 选项:无]; self = [对象objectAtIndex:0]; [对象释放];
但是我可以不用额外的工作就能做到吗?打字?
- 假设我定义了 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.
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 likeNSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"MySubclassOfViewController" owner:self options:nil]; self = [objects objectAtIndex:0]; [objects release];
But can I make it without extra work & typing?
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己解决了我的问题。经过一番研究,我得出了这些结论。
UITabBarController *tbc = [[UITabBarController alloc] initWithNib...
)要么应该有一个额外的控制器插座,或者控制器应该显式alloc
/init
'ed(但不是initWithNibName
),或者可以使用loadNibNamed
实例化代码>. 就是这样。原因是标签栏控制器没有声明将它们连接到子视图控制器的出口。 (有关加载笔尖的更多详细信息,请查看开发混沌理论博客)。对此有何评论? :)
I've solved my problem myself. After some research, I came to these conclusions.
UITabBarController *tbc = [[UITabBarController alloc] initWithNib...
) Either there should be an extra outlet for the controller, or the controller should be explicitlyalloc
/init
'ed (but notinitWithNibName
), or it could be instantiated usingloadNibNamed
. 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).Any comments on this? :)