我把2个xib文件放在bundle中。此捆绑包通过拖放添加到项目中。何时[super initWithNibName: @ "RUIBrowser.bundle / RUIBrowseriPhoneView.xib" bundle: nil];
应用程序崩溃时出现以下错误:
由于未捕获的异常而终止应用 'NSInternalInconsistencyException',原因:'无法加载NIB bundle:'NSBundle(loaded)',名称为'RUIBrowser.bundle / RUIBrowseriPhoneView.xib'
我做错了什么?
答案 0 :(得分:1)
我找到了解决方案。这很简单
NSBundle *bundle = [[NSBundle alloc] initWithPath:@"RUIBrowser.bundle"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self = [super initWithNibName:@"RUIBrowseriPadView" bundle:bundle];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
self = [super initWithNibName:@"RUIBrowseriPhoneView" bundle:bundle];
}
答案 1 :(得分:0)
使用此代码初始化笔尖。
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
[super initWithNibName:@"RUIBrowseriPhoneView" bundle: nil];
}
else
{
[super initWithNibName:@"RUIBrowseriPadView" bundle: nil];
}
答案 2 :(得分:0)
NSLog(@"nib path from bundle: %@", [self.yourNibBundle pathForResource:@"RUIBrowseriPhoneView" ofType:@"nib"]);
NSBundle *bundle = [NSBundle bundleWithPath:pathNibFile].
UIViewController *viewController = [[yourViewController alloc] initWithNibName:@"RUIBrowseriPhoneView" bundle:bundle];