2013-02-13 122 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