Skip to content

Instantly share code, notes, and snippets.

@ryanhanwu
Created October 3, 2012 07:12
Show Gist options
  • Select an option

  • Save ryanhanwu/3825531 to your computer and use it in GitHub Desktop.

Select an option

Save ryanhanwu/3825531 to your computer and use it in GitHub Desktop.
StoryBoard pass value between viewcontrollers
- (IBAction)passValueButton:(id)sender { //An action method
[self performSegueWithIdentifier:@"gotoView2" sender:self];
}
#pragma mark handle segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"gotoView2"]) {
User *user = [[User alloc] init];
user.name = "Ryan";
user.age = "26";
ViewController2* viewCtrl2 = segue.destinationViewController;
//the destination is View 2
viewCtrl2.user = user;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Name : %@", self.user.name);
NSLog(@"Age : %@", self.user.age);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment