iOS UIViewController Transitions - kgleong/software-engineering GitHub Wiki
UIViewController
Transitions
Navigation Controller
class ViewController: UIViewController {
@IBAction func didTapButton(_ sender: UIButton) {
// Instantiate the next view controller to display.
// This instantiates a view controller constructed in Interface Builder.
anotherViewController =
UIStoryboard(
name: "Main",
bundle: nil
).instantiateViewController(
withIdentifier: "com.example.SomeStoryboardIdentifier"
)
// Push the next view controller on the navigation controller stack and display
navigationController?.pushViewController(anotherViewContrroller, animated: true)
}
}
Segues
Segue Types
Name |
Description |
show |
Adds the destination view controller onto the navigation controller's stack. The destination view controller's view is made visible, and a back button is added, which allows navigation back to the previous (source) view controller. |
show detail |
|
present modally |
|
popover presentation |
|
custom |
|
References
How to Segue from a table view to a detail view
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// All segues for this UIViewController are handled by this method,
// so specific behavior must target via the segue's identifier, which is
// defined in the storyboard or programatically.
if segue.identifier == "showItemDetailSegueIdentifier" {
if let itemDetailViewController = segue.destinationViewController as? ItemDetailViewController {
// Table views return the selected index path, which can be
// used to pass the correct item to the detail view controller.
if selectedIndexPath = itemsTableView.indexPathForSelectedRow {
itemDetailViewController.item = items[selectedIndexPath.row]
}
}
}
}
References