Illep Illep - 1 month ago 9
Objective-C Question

Crash when passing string

My code crashes when passing a string parameter.

Can someone help me sort this? :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

NSIndexPath *indexPath = (NSIndexPath *)sender;

if ([[segue identifier] isEqualToString:@"abc"]) {

MyVC *myvc = [segue destinationViewController];
myvc.itemstring=@"dsdsds";

}

}


ERROR


-[UIViewController itemstring:]: unrecognized selector sent to instance 0x7fc89b0028d0

2016-10-14 14:54:24.118 Myapp[7824:109039] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason:
'-[UIViewController itemstring:]: unrecognized selector sent to
instance 0x7fc89b0028d0'


MyVC

#import <UIKit/UIKit.h>

@interface MyVC : UIViewController {
NSString* itemstring;
}

@property (nonatomic, strong) NSString* itemstring;

@end

Answer

The line in the error...

-[UIViewController itemstring:]: unrecognized selector sent to instance 0x7fc89b0028d0

This suggests that the destination of the segue is a UIViewController and not a MyVC.

You probably haven't set the subclass correctly in the storyboard.

You can update it here...

enter image description here

by changing the Class to MyVC.