2013-02-13 113 views
0

你好,我只是一個初學者。加載一個xib文件

我已經創建了一個新的xib文件。現在我試圖把它稱爲下面的代碼,但它不起作用。

這是我在文件的所有者已完成:

enter image description here

UIViewController *controller; 
controller = [[UIViewController alloc]initWithNibName:@"UserFeedback" bundle:nil]; 
[self.view addSubview:controller.view]; 

,我得到的錯誤是:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "UserFeedback" nib but the view outlet was not set.' 
+0

不要使用使用UIViewController只是使UIViewController的子類和使用該子類。而且xib也必須映射到該子類。 – Exploring 2013-02-13 06:25:07

+0

http://stackoverflow.com/questions/4763519/loaded-nib-but-the-view-outlet-was-not-set-new-to-interfacebuilder – 2013-02-13 06:54:43

+0

我懷疑它是否設置爲適當的類AFMoviePlayerController或不。 – 2013-02-13 06:55:49

回答

1

我希望,您已經創建了「控制器。 h「和」controller.m「UIViewController。

然後將類「控制器」放入「UserFeedback」.xib文件中。

並用「UserFeedback」.xib文件綁定視圖對象。

試試這個,讓我知道。

幾乎你會得到成功。

乾杯!

0

以下是您可以使用的技術:

UIViewController * controller; controller = [[UIViewController alloc] initWithNibName:@「UserFeedback」bundle:nil]; [self.view addSubview:controller.view];

上面的代碼是正確的,但第一u必須檢查控制器視圖約束力或不..我認爲錯誤是說你沒有約束力控制器視圖

0

下圖將幫助您瞭解

enter image description here

正如我可以從你的代碼中看到現在

ATMoviePlayerController *controller; 
controller = [[ATMoviePlayerController alloc]initWithNibName:@"UserFeedback" bundle:nil]; 
[self.view addSubview:controller.view]; 
+0

我已經映射文件的所有者的視圖,現在我沒有得到一個錯誤,但問題是什麼也沒有發生...... – 2013-02-13 06:34:57

+0

所以請映射它點擊fileowner比在右側面板點擊第三選項卡和自定義類提ur class – 2013-02-13 06:37:35

+0

我現在做了,但沒有任何反應。 – 2013-02-13 06:38:41

0

似乎出口中正確設置故事板,但同時在代碼中訪問它,你可能需要ammend一些代碼。

AFMoviePlayerController *controller = [[AFMoviePlayerController alloc]initWithNibName:@"UserFeedback" bundle:nil]; 
[self.view addSubview:controller.view]; 
+0

這沒有奏效,它做了一個線程錯誤 – 2013-02-13 23:37:41