2017-09-26 27 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() 
    } 
    } 
相關問題