objective-c - storyboard page jump and value transfer
PHP中文网
PHP中文网 2017-05-02 09:29:33
0
1
866

I checked some articles online and found some methods for storyboard page jump and value transfer. I tried it. Some are useful and some are not. Here they are summarized as follows (page A jumps to page B),
Jump method:
1. There is in A button and other controls, directly hold down the control key and drag to B, click the button to jump;
2. Hold down the control key to directly connect A and B, select the connection and add an Identifier (name it c). Create an action for the button in A, and implement the method [self performSegueWithIdentifier:@"c" sender:nil]; in the action to achieve jump

Value passing method:
1. Implemented in prepareForSegue, based on the connection Identifier. The value is passed successfully
2. Implement it in the action, find the page to jump through the storyboard id, realize the jump and pass the value UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ReceiveViewController *B = [storyboard instantiateViewControllerWithIdentifier:@"IdReceive"];
B.name = @"GC";
B.age = 10;
[self.navigationController pushViewController:receive animated:YES];

This method failed to pass the value, and the page could not jump, because A is a viewcontroller and not a navigationController, so I changed the last sentence to [self performSegueWithIdentifier:@"c" sender:nil]; The jump was OK, but Value transfer failed.

I would like to ask all the experts, how to jump and transfer value through storyboard id? Thanks!

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
Ty80
  1. Is your A placed inside the navigationviewcontroller? Then there is no need to change the last sentence

  2. If it is not in navgationviewcontroller, it depends on how you want to display your B. For example, if it is present, you can [self presentViewController:B animated:YES completion:nil]

  3. If you want to use [self performSegueWithIdentifier:@"c" sender:nil]; this way, you don’t need to get the B viewcontroller in the action. The code is modified as follows

- (void)someButtonClicked:(id)sender {
  [self performSegueWithIdentifier:@"c" sender:nil]
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender {
 if([segue.identifier isEqualToString:@"c"]){
    ReceiveViewController *B = segue.destinationViewController;
    B.name = @"GC"; 
    B.age = 10; 
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template