Unable to set property of a UIViewController ios

青春壹個敷衍的年華 提交于 2020-01-07 03:07:44

问题


I have a view controller which extends UIViewController.

@interface MyViewController : UIViewController
    @property (weak, nonatomic) IBOutlet UITextView *phoneTxt;
    @property (nonatomic, strong) NSDictionary *data;
@end

However when I try to set the property of the view controller by:

MyViewController *vvc = (MyViewController *)[sb instantiateViewControllerWithIdentifier:@"MyVC"];
vvc.data = data;

I get following error:

'NSInvalidArgumentException', reason: '-[UIViewController setData:]: unrecognized selector sent to instance 

I have checked, the view controller is not nil and I have synthesized the property data in MyViewController.m

@synthesize data = _data;

Why am I getting this error?


回答1:


I think you probably forgot to set the proper class for your view controller (File's Owner) in your storyboard/xib, so it probably gets instantiated as a raw UIWievController.



来源:https://stackoverflow.com/questions/32759088/unable-to-set-property-of-a-uiviewcontroller-ios

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