How to load xib file with attached view controller?

醉酒当歌 提交于 2019-12-23 07:30:59

问题


I am using a xib file as a back view in coverflow component . and it is seeing nicely .

The code for loading a xib file is :

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 .

How can I do so ?

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

Tell me if more details need to answer the question .

Thanks .


回答1:


I don't exactly understand your question. It seems like you want to instantiate a view controller with this xib as the view?

You can do that like this:

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

You should subclass UIViewController in order to hook up IBOutlets and IBActions. Make sure you set the view controller as the file's owner and hook up it's outlets.



来源:https://stackoverflow.com/questions/2825442/how-to-load-xib-file-with-attached-view-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!