【问题标题】:The application does not see xib file in the bundle应用程序在包中看不到 xib 文件
【发布时间】:2014-02-14 10:10:22
【问题描述】:

我将 2 个 xib 文件打包。并且这个包通过拖放添加到项目中。当[super initWithNibName: @ "RUIBrowser.bundle / RUIBrowseriPhoneView.xib" bundle: nil]; 应用程序崩溃并出现以下错误:

由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'无法加载 NIB bundle:' NSBundle (loaded) 'with name' RUIBrowser.bundle / RUIBrowseriPhoneView.xib'

我做错了什么?

【问题讨论】:

  • 尝试NSBundle * RUIbundle = [NSBundle bundleWithPath:absolutePath];并使用initWithNibName:@"RUIBrowseriPhoneView" bundle:RUIbundle
  • 你应该使用这个命名约定:RUIBrowserView~ipad.xib 和 RUIBrowserView~iphone.xib。然后你只需在你的代码中写 initWithNibName:@"RUIBrowserView"

标签: ios objective-c xcode


【解决方案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];
}

【讨论】:

    【解决方案2】:

    使用此代码初始化笔尖。

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        [super initWithNibName:@"RUIBrowseriPhoneView" bundle: nil];
    }
    else
    {
        [super initWithNibName:@"RUIBrowseriPadView" bundle: nil];
    }
    

    【讨论】:

      【解决方案3】:

      找到你的笔尖路径:

      NSLog(@"nib path from bundle: %@", [self.yourNibBundle pathForResource:@"RUIBrowseriPhoneView" ofType:@"nib"]);
      
      NSBundle *bundle = [NSBundle bundleWithPath:pathNibFile].
      
          UIViewController *viewController = [[yourViewController alloc] initWithNibName:@"RUIBrowseriPhoneView" bundle:bundle];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-29
        • 2012-04-02
        • 1970-01-01
        • 2020-06-29
        • 2018-01-22
        相关资源
        最近更新 更多