[100 Day Swift] fifth day: Implementing view jumps with code

Source: Internet
Author: User



Objective:



When Xcode launches storyboard, Xcode can be simpler and smarter to help us do some simple things and quickly build a base app, but as a "code farmer" accustomed to writing code, you still need to know how to implement these "simple" things through code.



View jumps in Swift



1. Jump to any Uiviewcontroller


var sb = UIStoryboard (name: "Main", bundle: nil)
var vc = sb.instantiateViewControllerWithIdentifier ("ChooseViewController") as ChooseViewController
self.presentViewController (vc, animated: true, completion: nil)

The above is for StoryBoard to set its own start controller.




2. Jump to the next view from the current view


var vc = AnswerViewController ()
self.presentViewController (vc, animated: true, completion: nil)

Implemented by presentViewController. 




3. Return to the previous view via dismissviewcontrolleranimated (completion:)


Self.dismissviewcontrolleranimated (True, Completion:nil)

Use dismissviewcontrolleranimated.


4.Modal Segue to channel Controller
By selecting a button in storyboard Design view and right-dragging to another view, you can create an action jump, but you need to overload the Func prepareforsegue (segue:uistoryboardsegue!, Sender: anyobject!) method, as follows:


override func prepareForSegue (segue: UIStoryboardSegue !, sender: AnyObject!) {
     var channelC: ChannelController = segue.destinationViewController as ChannelController
     channelC.delegate = self
     channelC.channelData = self.channelData
}

These methods should be the main way to implement the jump after the appearance of StoryBoard. Pay attention to implement prepareForSegue and the corresponding parameters.




5. By Navigationcontroller.pushviewcontroller (animated:) method


var webView = WebViewController ()
webView.detailID = data.newsID
// take the navigation controller and add subView
self.navigationController.pushViewController (webView, animated: true)


6. Via func popviewcontrolleranimated (), uiviewcontroller! pops up the topmost view and returns to the next view controller



7. Return to one of the views specified in the Navigationcontroller view stack via the Func Poptoviewcontroller (animated:), anyobject[]!






Not to be continued ...

[100 Day Swift] fifth day: Implementing view jumps with code


Related Article

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.