你好我在我的控制器中實現了一個UICollectionView
。我在每個單元上顯示了很多信息。當用戶單擊特定的單元格時,我想將單元格中的所有信息傳遞給另一個控制器。如何從被點擊的單元格中獲取信息collectionview
因爲我在數據庫中顯示數據庫中的所有數據,並且單元格正在動態生成,因此我認爲一種方法可能是將一個單元格中的記錄標識傳遞給此函數didSelectItemAtIndexPath
,然後在第二個控制器中再次查詢來自數據庫。但我認爲這不是好主意。並且我也不知道如何在這個函數didSelectItemAtIndexPath
中傳遞id或任何信息。
因此,在短期我想顯示在正在顯示在其中被點擊
在這裏,小區的其他控制器所有的信息是我的代碼
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath
indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell",
forIndexPath: indexPath) as! CardsCollectionCell
cell.usernameLabel.text = (((dict["\(indexPath.item)"] as?NSDictionary)!["Trip"] as?NSDictionary)!["userName"] as?NSString)! as String
cell.feeLabel.text = (((dict["\(indexPath.item)"] as?NSDictionary)!["Trip"] as?NSDictionary)!["fee"] as?NSString)! as String
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
}
嘿,我建議你創建一個模型類來在不同視圖之間共享數據。它會比傳遞選擇的全部信息更容易 –