2016-02-02 44 views
2

我正在iOS中創建一個靜態庫。我正在使用故事板文件。爲此,我創建了名爲'OfferWallResources.bundle'的資源包文件,其中我添加了名爲'Offerwall.storyboard'的故事板文件。我嘗試使用下面的代碼來訪問靜態庫裏面的情節提要:無法在iOS靜態庫內的資源包文件中訪問故事板

NSBundle *bundle = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"OfferWallResources.bundle"]; 
    UIStoryboard *s=[UIStoryboard storyboardWithName:@"Offerwall" bundle:bundle]; 

但我的應用程序與下面的錯誤而崩潰:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Offerwall' in bundle NSBundle (loaded)'

我也試圖訪問同一故事板文件目標項目使用相同的代碼並且工作正常。但是,我想在庫中訪問它。我不明白我的錯在哪裏。

回答

0

我認爲你沒有正確實例化這個包。試用[NSBundle bundleWithPath:][NSBundle bundleWithURL:]

+0

我試過使用[NSBundle bundleWithPath:]。現在獲取以下錯誤:Interface Builder文件中的未知類OfferwallViewController。此視圖控制器出現在我的故事板文件中,並使用代碼在庫中實例化它:OfferwallViewController * o = [s instantiateViewControllerWithIdentifier:@「OfferwallViewController」]; –

+0

而在故事板中,您有一個視圖控制器,其類設置爲OfferWallViewController,標識符爲「OfferwallViewController」?無論如何,這是另一個問題,讓故事板文件似乎工作。 – lluisgh

+0

如何處理第二個問題? –