NSObject loading UIView with nib but fileowner is UIViewController

I have a custom object which handles some operations with views. Basically it initializes a UIView with a nib file. But I want my viewcontroller to be responsible to handle IBActions. So I setted my viewcontroller to be the file owner and connected IBActions.

In my custom object I load nib file like this:

self.nibView = [[[NSBundle mainBundle] loadNibNamed:@"nibName" owner:delegate options:optionsDict] lastObject];

I setted delegate which is my UIViewController(kind of strange) to be the owner. So I was expecting my viewcontroller to handle IBActions but it did not. My custom object tried to respons the action and of course application crashed because of not responding to selector. How can I achieve that ?

Edit:

View Controller 视图控制器

Custom Object 自定义对象

Nib File 笔尖文件


The delegate is a protocol, the owner should be an object.

If your view controller conforms to the delegate protocol, you should set owner:self and ensure that the delegate property of the view is set to be your view controller. This can be done in IB using the IBOutlet, or in code by something like: self.nibView.delegate = self

链接地址: http://www.djcxy.com/p/87722.html

上一篇: 不可能将行添加到UITableView

下一篇: NSObject使用nib加载UIView,但是fileowner是UIViewController