Swift-推送和弹出UIViewController不起作用

我的0 1 0 1 0 0 1 1 ^ ^ | | U/L I/G 遇到问题。有谁知道为什么该代码不起作用? ViewControllers函数起作用...

A到B

print

从B到A

    @IBaction func editButtonTapped(_ sender: Any) {
    let imageCollectionView = self.storyboard?.instantiateViewController(withIdentifier: "ImageCollectionVC") as! ImageCollectionViewController
    imageCollectionView.delegate = self
    self.navigationController?.pushViewController(imageCollectionView,animated: true)
    print("editButtonTapped")
}



}

    extension ExampleViewController: ClassBDelegate {
            func childVCDidComplete( with image: UIImage?) {
                self.pickedImage = image!
            }
    }

那是我的完整项目:https://github.com/chriskonnerth/Wishlist

在我的情况下,ViewController A是 protocol ClassBDelegate { func childVCDidComplete(with image: UIImage?) } class ImageCollectionViewController: UIViewController,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{ @IBOutlet weak var imageCollectionView: UICollectionView! var delegate: ClassBDelegate? var tappedImage = UIImage() func collectionView(_ collectionView: UICollectionView,didSelectItemAt indexPath: IndexPath) { tappedImage = images[indexPath.row] delegate?.childVCDidComplete(with: tappedImage) navigationController?.popViewController(animated: true) } ,B是ExampleViewController

UPDATE

那是我的情节提要:

ImageCollectionViewController是右边的那个,ImageViewController是左边的那个。

Swift-推送和弹出UIViewController不起作用

z540878734 回答:Swift-推送和弹出UIViewController不起作用

在下面的代码行中检查navigationController实例:

self.navigationController?.pushViewController(imageCollectionView,animated: true)

如果self.navigationController为nil,则您可能没有在 ExampleViewController 中嵌入导航控制器。

然后,您需要将第一个控制器嵌入导航控制器。  To add navigation controller -

Embed navigation option

本文链接:https://www.f2er.com/3120916.html

大家都在问