【发布时间】:2011-06-12 19:54:52
【问题描述】:
我正在尝试做一些非常棘手的事情,但我仍然卡在一个点上。我正在尝试使用另一个 Nib 文件继承自另一个 UIViewController 的 Nib 文件来实例化 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 但它只调用它自己的nib 文件。在超类中,我尝试重写 initWithNibName:bundle: 方法并自己放置 nibName :
// MotherViewController
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:@"MotherViewController"
bundle:nibBundleOrNil])) {
// Custom initialization.
}
return self;
}
它只初始化并显示Mother Class 及其 IB 对象。我明白为什么,但我开始认为不可能做我想做的事。有什么建议吗?
编辑:
我会像这样使用我的 SonViewController:
SonViewController *son = [[SonViewController alloc]
initWithNibName:@"SonViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:son animated:YES];
[son release];
它应该显示儿子和母亲的 IB 对象...
问候,
kl94
【问题讨论】:
标签: iphone objective-c inheritance uiviewcontroller nib