如何从ViewController

时间:2017-09-26 08:40:27

标签: swift3

我是swift3和IOS的新手,我想从ParentViewController按钮单击调用UiCollectionviewcell类函数。这可能吗?

class BasicInfoCell: UICollectionViewCell, UIScrollViewDelegate{
    func abcd(){
        print("i m called from parent view")
    }
}

class PersonalInfoVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
    @IBAction func updateUserInfo(_ sender: UIButton) {        
            abcd()
        }
}

注意:不要让功能静止
我坚持这个。任何帮助将受到高度赞赏 请在downvoting之前给出理由。

1 个答案:

答案 0 :(得分:0)

是的,你可以调用单元格功能。试试这个代码。 (假设您的按钮超级视图是您的BasicInfoCell)

class PersonalInfoVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
    @IBAction func updateUserInfo(_ sender: UIButton) {        
       guard let cell = sender.superview? as? BasicInfoCell else {
           retrun 
       }
        cell.abcd()
    }
   }
相关问题