iosobjective-cuiviewcontroller

[UIViewController setRecipeName:]: unrecognized selector sent to instance


I am from Java, and I am 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. What has gone wrong?


Solution

  • 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.