2017-09-26 15 views
-1

私はswift3とIOSには新しく、ParentViewControllerボタンのクリックからUiCollectionviewcellクラス関数を呼び出したかったのです。これは可能ですか?ViewControllerから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する前に理由をお知らせください。

答えて

0

はい、セル機能を呼び出すことができます。このコードを試してください。 (ボタンスーパービューがBasicInfoCellであると仮定します)

class PersonalInfoVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{ 
    @IBAction func updateUserInfo(_ sender: UIButton) {   
     guard let cell = sender.superview? as? BasicInfoCell else { 
      retrun 
     } 
     cell.abcd() 
    } 
    } 
関連する問題