gpt4 book ai didi

ios - Collection Cell 未调用 RootViewController 中的函数(在代码应用程序中)

转载 作者:行者123 更新时间:2023-11-30 12:46:46 25 4
gpt4 key购买 nike

有问题。我有一个 collectionView Controller ,并试图给“didSelectRowIndex...”一个任务来调用我的 rootViewController 的函数。我没有使用主板。应用程序是用代码编写的。

Collection View 单元格属性:

class feedCell: UICollectionViewCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UINavigationControllerDelegate  { 

var messageController: MessageController?
var specificRoom = [Room]()

....

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.messageController?.selectedRoom()
let roomView = self.specificRoom[indexPath.row]
self.messageController?.showChatConrollerFoRoom(roomView)

print("This is cell \(Int)") //<--- PRINTS AND CORRECT INT
}

...

}

我的 rootViewController 标题:MessageController

class MessageController: UITableViewController, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

...

func showChatConrollerFoRoom(roomView: Room){
let roomLogController = ChatLogController(collectionViewLayout: UICollectionViewLayout())
roomLogController.roomView = roomView
navigationController?.pushViewController(roomLogController, animated: true)
print(12345678) //<---DOES NOT PRINT: FUNCTION NEVER CALLED :(
}

...
}

我是 collectionViews 的新手。不知道我在这里做错了什么。感谢您的帮助!

最佳答案

默认情况下,UICollectionViewControllerdelegatecollectionViewdidSelectItemAtIndexPath应在 UICollectionViewController 中实现方法,而不是 cell 中的方法。在您使用 UITableViewController 的情况下并添加了UICollectionView您自己将委托(delegate)设置为 MessageController也执行 didSelectItemAtIndexPath那里。

如果你让你的 cell delegate collectionView的,知道对于每个现有单元格,方法 didSelectItemAtIndexPath当用户选择cell时将被调用一次.

关于ios - Collection Cell 未调用 RootViewController 中的函数(在代码应用程序中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41539511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com