に問題があります。私は、collectionViewコントローラを持っていて、 "didSelectRowIndex ..."に私のrootViewControllerの関数を呼び出すタスクを与えようとしています。私はMAINSTORYBOARDを使用していません。アプリケーションはコードで書かれています。コレクションRootViewController(コードアプリケーションで)でセルが呼び出されない関数
コレクションビューのセルプロパティ:
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に新しいです。私がここで間違っていることを確かめない。あなたの助けに感謝します!
です。しかし、各セルにはまだ一意のindexPathがありますか?私はまだ少し混乱しています。私は今、 "... viewController"には、collectionViewの代理人が含まれていることを理解しています。しかし、私はcollectionViiewを** [怠惰なvar collectionView:UICollectionView = {let cv = UICollectionView()、cv.dataSource = Self; cv.delegate =セルフリターンcv}()** – Ketone
はい、メソッド 'didSelectItemAtIndexPath'では、各セルでindexPathが一意になります。そのindexPathにセルからアクセスする必要がある場合は、代わりにindexPathプロパティをセルをデキューするときに更新されるセル。しかし、セルに値を設定するだけであれば、indexPathはメソッドが現在どのセルにポピュレートしようとしているかを十分に伝えます。 –