问题描述:

I'm new to iPhone application development

I have a question about how to pass data from one view (xib file) to another storyboard?

for example,

I have "welcome.xib" which contains nameTextfield and nextButton ,user will type their name into nameTextfield and click next

the app will navigate to "main.storyboard" and display the text from nameTextfield.text on userNameLabel in "main.storyboard"

what I know so far:-

  • I know how to pass data between views (from one xib file to another xib file)
  • I know how to navigate from view(xib file) to another storyboard

Thanks in advance !! :)

网友答案:

Override the -prepareForSegue:sender: method in your ViewController you want to pass the information from.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    DetailViewController *sc = [segue destinationViewController];
    // Here you can set variables in detailViewController. For example if you had a NSString called name
    sc.name = @"name_here";
    // Or you could do
    [sc setName:@"name_here"];
}
相关阅读:
Top