Swift UI Special Training 42 use Swift code to implement page Jump and pass value, uiswift

Source: Internet
Author: User

Swift UI Special Training 42 use Swift code to implement page Jump and pass value, uiswift

Previously, if you want to click a button to jump to another button, sometimes we need to trigger page jump through some actions, such as shaking the mobile phone, in this way, you cannot directly use the link method to achieve the jump. How can you achieve the jump through code? The transition method is still used. In the storyboard, link the two pages to be redirected. Note that it is no longer limited to connecting objects such as buttons to another page, as long as the jump link is from one to the other, connect the two pages and select show as the link. This is not demonstrated here. Be sure to give this seuge a name, this is because we will see it later. Here we name it showDetail.



. For example, I need to shake my phone to jump to the next page and rewrite the following method on the first page:

Override func shouldw.mseguewithidentifier (identifier: String ?, Sender: AnyObject ?) -> Bool {if self. showArray. count! = 0 & self. markpoint! = 0 // your own judgment condition {return true} else {return false }}

The above method is used to determine whether the page can be redirected and add our own judgment conditions to it.

Then, in the method of capturing and shaking the mobile phone action (if you do not understand the captured code, you can refer to the article I wrote earlier and have an introduction), add our judgment jump conditions. If the jump is true, if the jump condition is not met, give your own warning:

Override func motionEnded (motion: UIEventSubtype, withEvent event: UIEvent) {if motion = UIEventSubtype. motionShake {if markpoint = 1 & self. searchpoint = false {// No jump is allowed. A warning is given: var alertController1 = UIAlertController (title: "No matching dishes! ", Message: nil, preferredStyle :. alert) var cancelAction = UIAlertAction (title: "return", style :. cancel, handler: nil) alertController1.addAction (cancelAction) self. presentViewController (alertController1, animated: true, completion: nil)} if self. searchpoint = true {// you can jump to self. extends mseguewithidentifier ("showDetail", sender: self) // jump to the next page and identify "showDetail "}}}

The ingress mseguewithidentifier method is used for redirection. If you want to use the transport board prepareForSegue, my code is as follows:

Override func prepareForSegue (segue: UIStoryboardSegue, sender: AnyObject ?) {If segue. identifier = "showDetail" {let destinationController = segue. destinationViewController as ShowTableViewController destinationController. navigationItem. title = "Shake to the dish" destinationController. tempCaipin = self. showArray // pass value }}

The first page:



Jump after shaking the phone:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.