展现下一个ViewController
-
PerformSegue()
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView){ performSegue(withIdentifier: "pinToAttendeeView", sender: nil) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "pinToAttendeeView" { // Get reference to the destination view controller let destViewController = segue.destination as! AttendeeMapViewController // Set the property to the selected location so when the view for // detail view controller loads, it can access that property to get the feeditem obj destViewController.selectedLocation = selectedLocation } }
-
Present() with UIApplication + instantiateViewController()
let rootVC = UIApplication.shared.keyWindow?.rootViewController let searchController = rootVC!.storyboard!.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController self.present(searchController, animated: true, completion: nil)
-
Present() with storyboard + instantiateViewController()
let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main) guard let machineDetailVC = mainStoryboard.instantiateViewController(identifier: "MachineDetailViewController") as? ViewController else { print("Couldnt find such VC") return }
-
Present() with init()
But this means IBOutlet wont be connected cuz ur not using storyboard or identifier. So you should create UI by code. Maybe outdated StackOverflowpresent(SomeViewController(), animated: true, completion: nil)