Tengo un UIViewController
llamado AController
.
Este despliega un segundo UIViewController
llamado BController
, pero lo hace en formato modal - overCurrentContext
.
BController
tiene 3 botones, cada uno lleva a un UIViewController
distinto, cada uno de estos 3 UIViewController
tiene un UINavigationViewController
.
El problema que tengo es que no se como hacer para acceder desde BController
a los otros UIViewController
sin perder la navegación ni el TopBarLayout
.
Mi código es este:
AController
Alamofire.request(urlString, method: .post, parameters: parametros).responseJSON { response in
if let result = response.data {
do {
let json = try JSON(data: result)
if json["resultado"] == "true" {
let modalViewController = BController()
modalViewController.modalPresentationStyle = .overCurrentContext
self.present(modalViewController, animated: true, completion: nil)
}
else {
self.mostrarAlerta(titulo: "Error", mensaje: "")
}
}
catch {
print("Error: \(error)")
self.mostrarAlerta(titulo: "Error", mensaje: "")
}
}
}
BController
import UIKit
class BController: UIViewController {
var viewPrincipal = UIView()
var btnAccion1 = UIButton()
var btnAccion2 = UIButton()
var btnAccion3 = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
let tamPantalla = UIScreen.main.bounds.size
let width = tamPantalla.width
let height = tamPantalla.height
viewPrincipal = UIView(frame: CGRect(x: 25, y: 90, width: width - 50, height: height - 120))
viewPrincipal.backgroundColor = UIColor.white
viewPrincipal.layer.borderColor = UIColor.black.cgColor
viewPrincipal.layer.borderWidth = 2
btnAccion1 = UIButton(frame: CGRect(x: 0, y: 0, width: width - 100, height: 50))
btnAccion1.setTitle("Accion 1", for: .normal)
btnAccion1.addTarget(self, action: #selector(accion1(_:)), for: .touchUpInside)
btnAccion2 = UIButton(frame: CGRect(x: 0, y: 0, width: width - 100, height: 50))
btnAccion2.setTitle("Accion 2", for: .normal)
btnAccion2.addTarget(self, action: #selector(accion2(_:)), for: .touchUpInside)
btnAccion3 = UIButton(frame: CGRect(x: 0, y: 0, width: width - 100, height: 50))
btnAccion3.setTitle("Accion 3", for: .normal)
btnAccion3.addTarget(self, action: #selector(accion3(_:)), for: .touchUpInside)
viewPrincipal.addSubview(btnAccion1)
viewPrincipal.addSubview(btnAccion2)
viewPrincipal.addSubview(btnAccion3)
view.addSubview(viewPrincipal)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@objc func accion1(_ sender: UIButton) {
if let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Controller1") as? Controller1 {
if let navigator = navigationController {
navigator.pushViewController(viewController, animated: true)
}
else {
print("Error 2")
if let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "NavegacionController1") as? NavegacionController1 {
present(vc, animated: true, completion: nil)
}
}
}
else {
print("Error 1")
}
}
@objc func accion2(_ sender: UIButton) {
}
@objc func accion3(_ sender: UIButton) {
}
@objc func cerrarVentana(_ sender: UIButton) {
print("Cerrar ventana")
self.dismiss(animated: true, completion: nil)
self.presentedViewController?.dismiss(animated: true, completion: nil)
}
}