Ios 未在viewController上调用协议
目前,我们有一个在位于collectionViewCell上的“didSelectItemAt indexPath”中激活的协议。这样做是为了将collectionViewCell嵌入到tableViewCell中,以便它可以侧向滚动。当按下collectionViewCell时,它应该转到另一个视图控制器。到目前为止,从未调用与协议关联的单元格的viewController。代码如下:Ios 未在viewController上调用协议,ios,swift,protocols,uicollectionviewcell,tableviewcell,Ios,Swift,Protocols,Uicollectionviewcell,Tableviewcell,目前,我们有一个在位于collectionViewCell上的“didSelectItemAt indexPath”中激活的协议。这样做是为了将collectionViewCell嵌入到tableViewCell中,以便它可以侧向滚动。当按下collectionViewCell时,它应该转到另一个视图控制器。到目前为止,从未调用与协议关联的单元格的viewController。代码如下: protocol handleKnownForImage { func knownForImageTap
protocol handleKnownForImage {
func knownForImageTapped(movieID: NSNumber)
}
//On TableViewCell
class KnownForCell : UITableViewCell {
var imageDelegete: handleKnownForImage?
var movieID: NSNumber?
}
extension KnownForCell: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Known For Cell Has Been Pressed")
self.movieID = knownForExtendedArray[indexPath.row].id
guard let movieID = movieID else {return}
imageDelegete?.knownForImageTapped(movieID: movieID)//This gets called
}
}
//On ViewController
extension PeopleDetailViewController: handleKnownForImage {
var knownForID: NSNumber?
func knownForImageTapped(movieID: NSNumber) {//This is never called
self.knownForID = movieID
performSegue(withIdentifier: peopleToDetailSegue, sender: self)
}
}
在哪里设置代理?您可能希望委托是一个弱属性,以避免强引用循环。您是否打印了消息?您是否在打印行上设置了断点,然后逐步通过?有两种可能的方式使代理在打印后不会被调用;movieID可以是nil,委托可以是nil。我刚刚意识到我忘了在cellForRowAt IndexPath中将委托设置为self