Home > Article > Web Front-end > Preliminary exploration of StoryBoard (3): Customizing Segue and transferring values between pages_html/css_WEB-ITnose
Among the three types of StoryBoard connections, one type is Custom. Developers can use custom Segue. Custom Segue classes need to inherit the class UIStoryBoardSegue and override the perform method. :
- (void)perform{ NSLog(@"使用自定义连接"); [self.sourceViewController presentViewController:self.destinationViewController animated:YES completion:nil];}
The operation effect is the same as using Modal type connection directly:
Of course, you can also customize Push type connections
If you want the content between pages to be related, you need to implement inter-page transfer Value. In StoryBoard, the page value is passed through the prepareForSegue:sender: method. First set the connection Identifier to 2vc2 (you can name it according to your own needs, just keep it consistent with the string in the code)
Drag and drop a UITextView instance to page 2 , and associate the output port recTextView
Add the following code in ViewController.m:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([[segue identifier] isEqualToString:@"2vc2"]) { ViewController2 *vc2 = (ViewController2 *)[segue destinationViewController]; vc2.passText = @"使用prepareForSegue:sender进行页面传值"; }}In ViewController2 Assign the value of passText to recTextView.text in .m
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. _recTextView.text = _passText;}