ravi ravi - 4 months ago 8
iOS Question

[UIViewController setRecipeName:]: unrecognized selector sent to instance

I am(from java); new to objective c and xcode. Below is the code which is building fine but throwing

unrecognized selector sent to instance
. I tried to fix it by googling.. but no luck.

if ([segue.identifier isEqualToString:@"myAccSegue"]) {
MyAccountController *destViewController = segue.destinationViewController;
NSString *s = @"avcd";//[_carImages objectAtIndex: (NSUInteger)index.section ];
destViewController.recipeName=s;
}


and MyAccountController is:

#import <UIKit/UIKit.h>

@interface MyAccountController : UITableViewController

@property NSInteger index;

@property (nonatomic,strong) NSString *recipeName;

@end


in MyAccountController.m i wrote
@synthesise recipeName
. When i run i get the error

2013-06-29 23:02:28.962 abcd[9171:c07] -[UIViewController setRecipeName:]: unrecognized selector sent to instance 0x7560cc0


A little debuggng shows ox7560cc0 belongs to
destinationViewController
. Not sure what has gone wrong..

Any help please?

Answer

The error message

-[UIViewController setRecipeName:]: unrecognized selector sent to instance ...

indicates that

MyAccountController *destViewController = segue.destinationViewController;

did not return a MyAccountController as expected, but a UIViewController.

A probable reason is that you did not set the "Custom Class" of the view controller to "MyAccountController" in the storyboard file.