我试图做一些非常棘手的事情,我仍然坚持一点。我试图用其他UIViewController
与另一个Nib文件继承的Nib文件实例化一个UIViewController
。
问题是当我实例化我的儿子UIViewController
。UIViewController与笔尖文件和继承
// SonViewController
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil
bundle:nibBundleOrNil])) {
// Custom initialization.
}
return self;
}
init方法initWithNibName:bundle:
应该叫super class
但只叫了自己的笔尖文件。在超类中,我试图重写initWithNibName:bundle:
方法,并把自己nibName这样的:
// MotherViewController
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:@"MotherViewController"
bundle:nibBundleOrNil])) {
// Custom initialization.
}
return self;
}
它仅init和显示Mother Class
和IB对象。我明白为什么,但我开始认为不可能做我想做的事。任何建议?
编辑:
我会用我的SonViewController就像这样:
SonViewController *son = [[SonViewController alloc]
initWithNibName:@"SonViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:son animated:YES];
[son release];
应该显示的儿子和母亲IB对象...
问候,
kl94
正如你所说,这是一个非常旧的帖子。但是现在,因为你,我/我们知道如何用2个xib创建2个视图控制器,并让它们从另一个继承。谢谢你 – klefevre 2014-04-17 10:06:32