推视图控制器无法从集合视图单元格中工作

时间:2019-07-10 08:45:19

标签: swift uicollectionviewcell navigationcontroller

当我尝试浏览新的视图控制器时,代码运行但不执行工作

  

单元格代码:

protocol NavigateViewControllerDelegate {
    func navigate(destination : String)
}

class LoginCell : UICollectionViewCell {
    var delegate : NavigateViewControllerDelegate?

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }

    func setupViews () {
        ...
        loginButton.addTarget(self, action: #selector(login), for: .touchUpInside)
        ...
    }

    @objc func login(){
        ...
        self.delegate = ViewController() as NavigateViewControllerDelegate
        self.delegate.navigate(destination: "MainMenu")
        ...
    }
}

并在视图控制器中:

class ViewController : UICollectionViewController,NavigateViewControllerDelegate {
    ...
    func navigate(destination: String){
        print("navigate to main menu")
        self.navigationController?.pushViewController(MainMenuVC(), animated: true)
    }
}

运行代码并完成打印指令,并在领事中打印“导航至主菜单”,但该应用程序未导航主菜单视图控制器

0 个答案:

没有答案