Three20 TTNavigator TTViewController 自动加载XIB
我想与您分享有关 Three20 框架的知识。
如果您使用 TTNavigator 并且您有来自 TTViewController 的子类的自定义 VC,这很烦人。它不会自动加载 NIB。
TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
[map from: @"app://myvc" toViewController: [MyVC class]];
有一个解决方法和非常优雅的解决方案。
只需创建 TTViewController 的另一个子类并覆盖该类即可:
- (void) loadView
{
[super loadView];
// load automatically the NIB
[[NSBundle mainBundle] loadNibNamed: NSStringFromClass([self class]) owner: self options: nil];
}
当第一次加载 VC 时,VC 将自动加载 NIB。
I thought I want to share my knowledge with you around Three20 framework.
It is annoying if you use TTNavigator and you have custom VC that is subclass from TTViewController. It does not load the NIB automatically.
TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
[map from: @"app://myvc" toViewController: [MyVC class]];
There is a workaround and pretty much elegant solution.
Just make another subclass of TTViewController and overrides the class to have this:
- (void) loadView
{
[super loadView];
// load automatically the NIB
[[NSBundle mainBundle] loadNibNamed: NSStringFromClass([self class]) owner: self options: nil];
}
The VC will load the NIB automatically when the VC is being loaded for first time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例目录中的 TTNibDemo 项目有一个 VC,它是 TTViewController 的子类。该 VC 有一个 nib,它使用 AppDelegate 中的函数加载 nib。检查一下这是否对您不起作用。
The TTNibDemo project in the samples directory has a VC which is a subclass of TTViewController. This VC has a nib and it loads the nib with a function in the AppDelegate. Check it out if this does not work for you.