Unable to set property of a UIViewController ios

2019-09-07 22:06发布

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条回答
看我几分像从前
2楼-- · 2019-09-07 22:45

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.

enter image description here

查看更多
登录 后发表回答