Initwithnibname:bundle:无法从资源包中加载2个视图控制器的xib
问题描述:
问题的后半部分可能不重要;但我有一个问题加载2个视图控制器从我已经放入资源包的xib。Initwithnibname:bundle:无法从资源包中加载2个视图控制器的xib
这些是我所采取的步骤:
1)创建一个新的目标,捆绑型的。在复制资源包中,我添加了这个包所需的xib。
2)增加了这个包在我的主要应用目标的目标的依赖,从而将建立与厦门国际银行
3)在我的产品组包,出现在捆绑,我拖着这将参考在我的主要应用程序目标的构建阶段中复制包资源。
4)我运行和构建,并尝试与
self.accountController = [myAccountController initWithAccount:account];
//At this point, accountController is initialized correctly,
//but neither of the view controllers are initialized;
//so this view is nil. see below for more info
NSView* myView = self.accountController.myViewController1.view;
加载笔尖在我windowcontroller //这是执行的AccountController:
//This method is custom, because I need some arguments in my init
-(instancetype) initWithAccount:(myAccount*)account
{
self = [super initWithNibName:myNibName bundle:[self resourceBundle]
if(self)
{
self.account = account;
}
return self;
}
+(NSBundle*) resourceBundle
{
NSURL* bundleURL = [[NSBundle mainBundle] URLForResource:myBundleName withExtension:@"bundle"];
NSBundle* bundle = [NSBundle bundleWithURL:bundleURL];
NSError* error = nil;
[bundle loadAndReturnError:&error];
NSLog(@"%@", error);
return bundle;
}
返回的包是正确的,它指向正确的位置,并且所有名称都是正确的。但在initWithNibName:bundle:
调用之后,我自己没有在笔尖中定义的2个视图控制器。
我想说这与initwithnibname不会实际加载包含视图控制器的nib有关?但我的理解是shakey,而苹果笔记本文档并没有真正达到我。我也可以在我的xib中创建我的VC的错误...
有人能帮我拼出来吗?基本上我花了整整一天的时间把我的头撞到这里。提前致谢!
答
韦尔普我敢肯定有一个更好的解决办法,但我最终只是访问基视图控制器的view
属性,然后它会去加载在厦门国际银行宣布视图控制器