有问题。我有一个collectionView控制器,我试图给“didSelectRowIndex ...”一个任务来调用我的rootViewController函数。我没有使用MAINSTORYBOARD。应用程序是用代码编写的。
集合查看单元格属性:
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的新手。不知道我在这里做错了什么。感谢您的帮助!
答案 0 :(得分:0)
默认情况下,UICollectionViewController
是其delegate
的{{1}}。 collectionView
应在didSelectItemAtIndexPath
方法中实施,而不是在UICollectionViewController
范围内实施。在您使用cell
并自己添加UITableViewController
的情况下,请将代理设置为UICollectionView
并在那里实施MessageController
。
如果您didSelectItemAtIndexPath
cell
delegate
,请知道对于每个现有单元格,当用户选择方法时,方法collectionView
将被调用一次didSelectItemAtIndexPath
。