當使用 initWithNibName 函數, 並使用 由nib文件生成的ViewController 的view屬性時候,遇到這個問題。 html //load loc.xib app UIViewController * UIVC = [[UIViewController alloc] initWithNibName:@"loc" bundle:nil]; 函數 [self.view addSubview:UIVC.view]; spa [UIVC release]; htm NibName[2203:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "loc" nib but the view outlet was not set.'blog 表面意思是指 咱們加載的nib文件,"view" 屬性值沒有進行設置. ci 這裏的實際狀況: 不是所生成的 VC 的view屬性值爲 nil, 而是所生成的 VC 沒有 view 這個屬性。 咱們使用的是UIViewController 定義的VC, 爲何 VC (View Controller) 會沒有 view 屬性呢? get (多麼具備邏輯性的表述都不如一次成功的完整操做,begin :) 編譯器 解決方案: it 1. 點擊咱們要加載的 xib 文件 2. 在右邊選中 File's Owner ![image image](http://static.javashuo.com/static/loading.gif)
3. 在 File's Owner 的 選項卡的「Custom Class」 屬性設置中,將 Class 的值改爲對應的 VC, 這裏改爲 UIViewController, ![image image](http://static.javashuo.com/static/loading.gif)
![image image](http://static.javashuo.com/static/loading.gif)
4. 這時候,在File's Owner 的 選項卡中, 就 會出現「待鏈接設置」 的 view 屬性, 也即咱們的編譯器 告訴咱們的 the view outlet was not set 中的 view。當 File's Owner 的 class 爲 NSObject 時候,是沒有 view 屬性的。 ![image image](http://static.javashuo.com/static/loading.gif)
鏈接 view 屬性, ![image image](http://static.javashuo.com/static/loading.gif)
5. win+r, OK. |