0

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?

Ajax
  • 1,689
  • 4
  • 20
  • 29
  • Are you sure that `MyViewController *vvc = (MyViewController *)[sb instantiateViewControllerWithIdentifier:@"MyVC"];` line of code gives you instance of `MyViewController` class ? Looking at your error it might be returning `UIViewController` class instance. – Tushar J. Sep 24 '15 at 10:34
  • In your storyboard you forgot to change the class of your viewController, take a look – Roberto Ferraz Sep 24 '15 at 10:35
  • The issue got resolved, but it seems like my app now enters an infinite loop. :/ it keeps calling [NSLocalizableString length] – Ajax Sep 24 '15 at 10:38
  • I was trying to fix this issue: http://stackoverflow.com/questions/32736496/instantiating-modal-view-controller-freezes-the-app?noredirect=1#comment53323268_32736496 – Ajax Sep 24 '15 at 10:39
  • Just so you know you don't need to do the `@synthesize` anymore this will be done automatically for you when you declare your property. Bin `@synthesize data = _data;` off completely it isn't need and is just a waste of space. – Popeye Sep 24 '15 at 11:09

1 Answers1

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.

enter image description here

Maciek Czarnik
  • 5,950
  • 2
  • 37
  • 50