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
[segue destinationViewController]
seems to be aUIViewController
object and not aMyVC
object. In InterfaceBuilder, you didn't set the class to theUIViewController
toMyVC
. - Larme