Domanda

I need to pass data (NSString) between two views. in the first view, I use ViewCollection to build grid so I have one button that I set the segue between the two views But in one button I need to change the segue so I use this code

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"radioPlayer"];
[self presentViewController:vc animated:NO completion:nil];

and I pass to the third View and is fine. But I need to pass Data (NSString ) so I read and find this task – initWithIdentifier:source:destination: but I don't know how to use this task. if someone knows how to use it helps me a lot.

È stato utile?

Soluzione

There are plenty of ways to pass data between the controllers, but the simplest one here would be for you to add an NSString property in the header file of your radioPlayer, and then just pass the data to it, for example:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"radioPlayer"];
vc.myStringData = @"Data that needs to be passed.";
[self presentViewController:vc animated:NO completion:nil];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top