简体   繁体   English

如何使用附加的视图控制器加载xib文件?

[英]How to load xib file with attached view controller?

I am using a xib file as a back view in coverflow component . 我使用xib文件作为coverflow组件中的后视图。 and it is seeing nicely . 它很好看。

The code for loading a xib file is : 加载xib文件的代码是:

NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TestMine" owner:nil options:nil];
        backView = [array objectAtIndex:0];

Now I want to attach a view controller with this xib without changing the current code . 现在我想在不更改当前代码的情况下使用此xib附加视图控制器。

How can I do so ? 我怎么能这样做?

I am getting the error : Exception :*** -[UIViewController superview]: unrecognized selector sent to instance 0x5891120 我收到错误: Exception :*** -[UIViewController superview]: unrecognized selector sent to instance 0x5891120

Tell me if more details need to answer the question . 如果有更多细节需要回答这个问题,请告诉我。

Thanks . 谢谢 。 替代文字

I don't exactly understand your question. 我不完全理解你的问题。 It seems like you want to instantiate a view controller with this xib as the view? 看起来你想用这个xib作为视图来实例化一个视图控制器?

You can do that like this: 你可以这样做:

[[UIViewController alloc] initWithNibName:@"TestMine" bundle:nil];

You should subclass UIViewController in order to hook up IBOutlets and IBActions. 你应该继承UIViewController,以便连接IBOutlets和IBActions。 Make sure you set the view controller as the file's owner and hook up it's outlets. 确保将视图控制器设置为文件的所有者并连接它的出口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM