我有两个viewControllers,还有一个viewController和viewController内部,还有一个viewContainer,它显然也是viewController。
问题是我希望当用户单击viewController(容器视图)中的按钮时,运行一个方法和另一个viewController的方法。
我在viewController(containerView)中有下一个代码
protocol ubicacionContainerViewControllerDelegate {
func cambiarContainer(posicion : Int)
}
class ubicacionContainerViewController: UIViewController {
var delegate :ubicacionContainerViewControllerDelegate?
//i am using tables is for that reason i have this code but when the user select a
// row i want to run a other method in other viewController
func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
let celda_seleccionada = tableView.cellForRow(at: indexPath) as!
celdaUbicacionContainerTableViewCell
ReservaViewController.reserVaServicio.lugar = "\(celda_seleccionada.lbPais) en \
(celda_seleccionada.lbCiudad) "
delegate?.cambiarContainer(posicion: 5)
}
现在在另一个viewController中,我具有以下代码:
class ReservaViewController: UIViewController,ubicacionContainerViewControllerDelegate {
func cambiarContainer(posicion: Int) {
//self.posicion = posicion
if(posicion == 5){
print(posicion)
}
}
现在我要对代表另一个viewController的ReservaViewController怎么说,或者我该怎么做?使用委托我运行了它,但是方法cambiarContainer无法运行