Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Please help me..

I want to pass data between different controllers in storyboard. For Example.

First View Controller

NSString *firstValue;

firstValue = @"First Number";

Now I want to send this to the result view controller and store in

NSString *resultFromFirstVC;

and show in label.

[label setText: resultFromFirstVC];

so the label show:

First Number

Xcode StoryBoard

share|improve this question

1 Answer

up vote 3 down vote accepted

Use this method to pass the property in all of your view controllers

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"ShowNewVC"]) {
        NextViewController *nextVC = (NextViewController *)[segue destinationViewController];
        nextVC.someProperty = self.myProperty;
    }
}

Change the name of "NextViewController" to match yours. Be sure to add the "Segue Identifiers" in your Storyboard file.

This should work. However, when you have to pass this property trough so many view controllers, you can consider creating a Singleton "Data Manager" object to store the data. The View Controllers would have access to the data through the singleton.

Good luck!

share|improve this answer
 
I use the [Segue destinationViewController] but it seems the prepareSegue() allows data to be added and subsequently moved to the adjacent view (i.e. view three to view two). Do you have any sample project or link for using Singletion "Data Manager" to understand and get command on it. –  user777304 Jan 4 at 9:27
2  
Yes. Here is a nice tutorial/guide galloway.me.uk/tutorials/singleton-classes –  Nikola Kirev Jan 4 at 9:58
1  
Create a singleton. The "someProperty" on the example should be used to store this string that you need to pass along. In the first view controller you should use something like this [[MyManager sharedManager] setSomeProperty:firstValue]; And in the fourth view controller use NSString *theString = [[MyManager sharedManager] someProperty]; –  Nikola Kirev Jan 4 at 10:01
 
Thank You so much.. It helped alot.. Solve my problem.. –  user777304 Jan 4 at 12:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.