自定义 UINavigationController 实现
我的应用程序中有一个 TabBarController,其中有一些导航控制器。我已经在界面生成器中简单地制作了所有这些东西。
现在我想实现我的自定义导航控制器,因此我创建了一个类:
#import <UIKit/UIKit.h>
@interface DetailNavigationController : UINavigationController
@end
@implementation DetailNavigationController
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (self) {
NSLog(@"I work!");
}
return self;
}
- (void) dealloc {
[super dealloc];
}
@end
在界面生成器中,我将此类作为自定义类添加到我想要的导航控制器中。现在,当我启动应用程序并选择带有此导航控制器的选项卡时,它可以工作,但不会调用 initWithRootController 。我猜它完全忽略了该类并作为默认导航控制器运行。
我是否需要在界面生成器中指定更多内容,或者是否需要在选项卡委托中的某处以编程方式指定此控制器?
谢谢。
I've got a TabBarController in my app and in it I've got a few NavigationControllers. I've got all this stuff simply made in interface builder.
Now I want to implement my custom navigationcontroller so I created a class:
#import <UIKit/UIKit.h>
@interface DetailNavigationController : UINavigationController
@end
@implementation DetailNavigationController
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (self) {
NSLog(@"I work!");
}
return self;
}
- (void) dealloc {
[super dealloc];
}
@end
And in Interface builder I added this class as Custom Class to the navigation controller I want. Now when I start the app and select the tab with this navigation controller it works but the initWithRootController is not called. I guess it's completely ignoring the class and runs as default navigation controller.
Do I need to specify anything more in interface builder or do I need to specify this controller programatically somewhere in tabbar delegate?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在界面生成器中创建导航控制器,则需要重写
initWithCoder:
,而不是initWithRootViewController:
。 xib 包含对象的实例化版本,并已设置根视图控制器。If you're creating the navigation controller in interface builder, you will need to override
initWithCoder:
, notinitWithRootViewController:
. The xib contains an instantiated version of your object, with the root view controller already set.