I have a SourceViewController and a DesViewController , there’s a variable in DesViewController : @property ( nonatomic , assign , readwrite ) NSString* name ;
but here’s a problem when I call the method in SourceViewController :
-(void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil ] ;
DestinationViewController* desViewController = [storyboard instantiateInitialViewController ] ;
desViewController.name = @"haah" ;
[self presentViewController:desViewController animated:YES completion:nil ] ;
}
the output :
'NSInvalidArgumentException', reason: '-[SourceViewController setName:]: unrecognized selector sent to instance 0x6a0d7c0'
Can anyone help me, please?
As it is right now, the viewcontroller you instantiate doesnt seem to be of class DestinationViewcontroller (since your initial viewController doesn’t seem to be of that class). So it doesnt have that property. You have to instantiate the correct class (see below).
Also check if you synthesized the property in implementation of DestinationViewcontroller.
And on a side note: though you may want to simply assign the string variable to a new value, most of the times you’d want to use copy instead of assign on NStrings. Also, the readwrite is not necessary since its the default behaviour.
So, better change your property declaration thusly:
And in implementation check if you synthesize for example like this:
And in your dealloc:
Also, consider using ARC if you stat a new project.
Now, if you make your viewController a DestinationViewcontroller, it should work.
Best way to get is would be