2013-03-20 65 views
3

我正在嘗試將所有.xib資源捆綁到「ViewController.bundle」中,以便與「MyLibrary.framework」一起發貨。如果我只是把在框架項目中的所有文件的.xib,一切工作正常,但如果我把它們「ViewController.bundle」裏,一切都掰開NSInternalInconsistencyException - 無法在軟件包中加載NIB:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Could not load NIB in bundle: 
'NSBundle </Users/administrator/Library/Application Support/iPhone Simulator/5.0/ 
Applications/8AD68FD1-158E-4926-AE03-8FEF870E7012/ios.app/ViewController.bundle> 
(not yet loaded)' with name 'FirstViewController_iPhone'' 
*** First throw call stack: 
(0x160e052 0x1071d0a 0x15b6a78 0x15b69e9 0x3ff838 0x2a6e2c 0x2a73a9 0x2a75cb 0x2c2b89 0x2c29bd 
0x2c0f8a 0x2c0d7e 0x2c0a22 0x2bfd88 0x5e3ac 0x2df8 0x2e34 0x160fec9 0x1e45c2 0x1e455a 0x289b76 
0x28a03f 0x2892fe 0x209a30 0x209c56 0x1f0384 0x1e3aa9 0x1eedfa9 0x15e21c5 0x1547022 0x154590a  
0x1544db4 0x1544ccb 0x1eec879 0x1eec93e 0x1e1a9b 0x2452 0x2385) 

我已經嘗試了各種方式: 1。在Finder中創建「ViewController.bundle」,將所有.xib放在那裏,然後拖動到xcode 2.爲框架項目創建一個新的Target,在「OS X」部分的「Framework & Library」下選擇「Bundle」注意:因爲我使用的xcode 4.6在它的「Framework & Library」下沒有「Bundle」,所以它必須是OSX,它曾經有,而且我用這個嚮導創建包含.png資源的bundle。

在這兩種情況下,我已經確定「BuildController.bundle」存在於我的目標應用程序中的「Build Phase」>>「Copy Bundle Resources」中。 我也嘗試過在我的Framework項目的「目標依賴項」下包含「ViewController.bundle」,但是我所有的努力都導致了同樣的崩潰。

我也試過各種方式來加載.xib,無濟於事。但是,下面的代碼加載來自相同的「ViewController.bundle」爲.png資源完美的作品:

// Loading .png resource works perfectly 
// UIImage* closeImage = [UIImage imageNamed:@"ViewController.bundle/first.png"]; 
// NSString *szBundlePath = [[NSBundle mainBundle] pathForResource:@"ViewController" ofType:@"Bundle"]; 
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"showView" message:szBundlePath delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
// UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)]; 
// [imageView setImage:closeImage]; 
// [alertView addSubview:imageView]; 
// [alertView show]; 
// return; 

使用相同的代碼加載廈門國際銀行失敗:

NSBundle *bViewController = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"ViewController" withExtension:@"bundle"]]; 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
    self.m_pFirstViewController = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:bViewController] autorelease]; 
    self.m_pSecondViewController = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:bViewController] autorelease]; 
} else { 
    self.m_pFirstViewController = [[[FirstViewController alloc] initWithNibName:@"ViewController.bundle/FirstViewController_iPad" bundle:nil] autorelease]; 
    self.m_pSecondViewController = [[[SecondViewController alloc] initWithNibName:@"ViewController.bundle/SecondViewController_iPad" bundle:nil] autorelease]; 
} 

    /** It crash in this line!! Note however, both m_pFirstViewController and m_pSecondViewController is allocated and not nil */ 
self.viewControllers = @[self.m_pFirstViewController, self.m_pSecondViewController]; 

    /** never reach here already crash */ 
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:self animated:YES completion:^{ 
    NSLog(@"presented!"); 
}]; 

我已經花了最後8小時調試這個,谷歌搜索和嘗試各種建議,但無濟於事......任何幫助,非常感謝!謝謝!

+0

我可以從xib中刪除一些控件,並將它與xib配對。 – 2013-03-20 10:18:05

+0

不,所有的.xib都包含在內,但是,我檢查了.app內的.bundle,它們都是按原樣包含的。即:.xib,但錯誤似乎是期待編譯版本(.nib) – Zennichimaro 2013-03-21 03:01:21

回答

2

我嘗試的第二種方法是最接近的......然後在Build Settings中將OSX包修改爲iOS包。顯然,我錯過了幾個步驟。我跟着馬特加洛韋這裏的教程和示例項目:

http://www.galloway.me.uk/tutorials/ios-library-with-resources/

,現在一切按預期工作。

感謝大家的幫助!

+0

謝謝!補充說明:如果你的png文件被轉換成tiff,添加這個「用戶定義的」構建設置: 'COMBINE_HIDPI_IMAGES = NO' – MechEthan 2013-04-12 17:34:13

相關問題