Home > Web Front-end > HTML Tutorial > 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
Release: 2016-06-24 11:51:46
Original
1365 people have browsed it

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];}
Copy after login

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进行页面传值";    }}
Copy after login
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;}
Copy after login

Simulator running:






source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template