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