无法通过Delegate / Protocol访问父VC中的func

问题描述

无法通过委托/协议从子级访问父视图控制器中的功能。 print()不打印。

在儿童VC中,我有这个:

protocol MyViewControllerDelegate: class {
    func requestExpandedView()
}
    
class MyViewController: UIViewController {
        
    weak var delegate: MyViewControllerDelegate?
    ...

    func collectionView(_ collectionView: UICollectionView,didSelectItemAt indexPath: IndexPath) {

        print("\(indexPath) didSelectItemAt")
        
        delegate?.requestExpandedView()  
    }
}

在上级VC中,我有这个:

extension MessagesViewController: MyViewControllerDelegate {
    func requestExpandedView() {
        print("Done") // doesn't print anything
        requestPresentationStyle(.expanded)
    }
}

怎么了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)