Home  >  Article  >  Web Front-end  >  Preliminary exploration of StoryBoard (3): Customizing Segue and transferring values ​​between pages_html/css_WEB-ITnose

Preliminary exploration of StoryBoard (3): Customizing Segue and transferring values ​​between pages_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:51:461348browse

Custom Segue

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];}

Ctrl connect the button of ViewController to ViewController2, and select the Segue type as Custom, click Connect, and set the connection category to the just customized PresentSegue.



The operation effect is the same as using Modal type connection directly:


Of course, you can also customize Push type connections


Page value transfer

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;}

Simulator running:






Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn