initWithNibName ...方法未触发
在我的基于导航的应用程序中,initWithNibName 方法不会被调用/触发
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
我正在 appdelegate 中定义 rootViewController (calViewController),如下所示
calViewController *objCalViewController = (calViewController *) [navController topViewController];
objCalViewController.context = [self managedObjectContext];
[window addSubview:navController.view];
[window makeKeyAndVisible];
这是问题所在吗?请给我帮助
In my navigation based application, initWithNibName method does not called/fire
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
I'm defining rootViewController (calViewController) in appdelegate like this
calViewController *objCalViewController = (calViewController *) [navController topViewController];
objCalViewController.context = [self managedObjectContext];
[window addSubview:navController.view];
[window makeKeyAndVisible];
Is this is the issue? Please give me a help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您的
UIViewController
在 nib 文件或 Storyboard(通常作为IBOutlet
)中定义时,不会调用initWithNibName:bundle:
,而是>initWithCoder:
是。当您使用 Interface Builder 将UIViewController
设置为UITabBarController
或UINavigationController
的一部分时就会出现这种情况,并且在使用 Storyboard 时几乎总是如此。When your
UIViewController
is defined in a nib file or Storyboard (usually as anIBOutlet
),initWithNibName:bundle:
is not called, ratherinitWithCoder:
is. This is the case when you use Interface Builder to set yourUIViewController
as part ofUITabBarController
orUINavigationController
, and almost always when using Storyboards.在你的 appdelegate.m 中这样做
in your appdelegate.m do like this
好吧,假设我有一个名为
TCViewController
的 viewController,并且位于
TCViewController.m
中我正在重写下面的方法。
在我的 RootViewController 中,我想像这样初始化 TCViewController
RootViewController.m
如果你像这样初始化一个 viewController,控制权将传递给子类中的 initWithNibName 方法(如果你已经实现了它)。
Ok lets say i have a viewController named
TCViewController
withand in
TCViewController.m
i am overriding the below method.
In my RootViewController i want to initialize TCViewController like this
RootViewController.m
If you initialize a viewController like this, control will pass to the initWithNibName method in your subclass if you have implemented it.