0
votes

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
1
Update your question with MyVC controller - Himanshu Moradiya
show the error. - Anbu.Karthik
whats the use of NSIndexPath *indexPath = (NSIndexPath *)sender; in here - Anbu.Karthik
What's in the crash log? And which line is crashing? - Fogmeister
[segue destinationViewController] seems to be a UIViewController object and not a MyVC object. In InterfaceBuilder, you didn't set the class to the UIViewController to MyVC. - Larme

1 Answers

4
votes

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.