una passing pasar pantalla otro otra entre datos data ios swift uinavigationcontroller viewcontroller uinavigation

ios - passing - Cómo navegar de un controlador de vista a otro usando Swift



pasar de una pantalla a otra swift (9)

Cree un archivo rápido (SecondViewController.swift) para el segundo controlador de vista y en la función apropiada escriba esto:

let secondViewController = self.storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as SecondViewController self.navigationController.pushViewController(secondViewController, animated: true)

Swift 2+

let mapViewControllerObj = self.storyboard?.instantiateViewControllerWithIdentifier("MapViewControllerIdentifier") as? MapViewController self.navigationController?.pushViewController(mapViewControllerObj!, animated: true)

Swift 4

let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "IKDetailVC") as? IKDetailVC self.navigationController?.pushViewController(vc!, animated: true)

Me gustaría navegar de un controlador de vista a otro. ¿Cómo puedo convertir el siguiente código Objective-C en Swift?

UIViewController *viewController = [[self storyboard] instantiateViewControllerWithIdentifier:@"Identifier"]; UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:viewController]; [self.navigationController pushViewController:navi animated:YES];


En Swift 4.1 y Xcode 9.3

Aquí AddFileViewController es el segundo controlador de vista.

La ID del guion gráfico es AFVC

let next = self.storyboard?.instantiateViewController(withIdentifier: "AFVC") as! AddFileViewController self.present(next, animated: true, completion: nil) //OR let dashboard = self.storyboard?.instantiateViewController(withIdentifier: "DBVC") as! DashboardViewController self.navigationController?.pushViewController(dashboard, animated: true)


En mi experiencia, navigationController era nulo, así que cambié mi código a este:

let next = self.storyboard?.instantiateViewControllerWithIdentifier("DashboardController") as! DashboardController self.presentViewController(next, animated: true, completion: nil)

No olvides configurar ViewController StoryBoard Id en StoryBoard -> identity inspector


En veloz 3

let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "NextViewController") as! NextViewController self.navigationController?.pushViewController(nextVC, animated: true)


En veloz 4.0

var viewController: UIViewController? = storyboard().instantiateViewController(withIdentifier: "Identifier") var navi = UINavigationController(rootViewController: viewController!) navigationController?.pushViewController(navi, animated: true)


Si no desea que aparezca el botón Atrás (que era mi caso, porque quería presentarlo después de que un usuario inició sesión), aquí se explica cómo configurar la raíz del controlador de navegación:

let vc = self.storyboard?.instantiateViewControllerWithIdentifier("YourViewController") as! YourViewController let navigationController = UINavigationController(rootViewController: vc) self.presentViewController(navigationController, animated: true, completion: nil)


SWIFT 3.01

let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "Conversation_VC") as! Conversation_VC self.navigationController?.pushViewController(secondViewController, animated: true)


Swift 3

let secondviewController:UIViewController = self.storyboard?.instantiateViewController(withIdentifier: "StoryboardIdOfsecondviewController") as? SecondViewController self.navigationController?.pushViewController(secondviewController, animated: true)


let objViewController = self.storyboard?.instantiateViewController(withIdentifier: "ViewController") as! ViewController self.navigationController?.pushViewController(objViewController, animated: true)