我找到了一個新的View Controller。該視圖控制器包含來自相應的CollectionViewCell的數組數據。如何更改數據以顯示前一個單元格數組?不必回到最後一個視圖控制器並從那裏選擇單元格?我正在使用Swift 3以下是解釋我的意思的圖像在ViewController中查找indexPath
第一個圖像位於第一個視圖控制器中。第二張和第三張圖片是在列表中的前兩張中的任何一張被點擊時顯示的內容。您可以使用第二個視圖控制器中的箭頭鍵轉到下一個索引。我如何實現這一功能?
let dataSource = DataSource()
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if inSearchMode {
return filteredAnimal.count
}
return dataSource.anim.filter{ $0.isDefault! }.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AnimIndex", for: indexPath as IndexPath) as! AnimIndex
let animal: Animal
if inSearchMode {
animal = filteredAnimal[indexPath.row]
} else {
animal = dataSource.anim.filter{ $0.isDefault! }[indexPath.row]
}
cell.configureCell(animal)
return cell
}
正如我可以從你的問題理解你想刷新在以前的viewcontroller數據。以下幾種方法可以做到這一點 1.從當前視圖控制器創建委託和呼叫。 2.將當前視圖控制器的通知發佈到前一個視圖控制器。 –
根據我的理解,我認爲您需要將所有collectionview單元格數據傳遞到下一個視圖控制器,以便您現在具有所有數據,因此您需要選擇 下一個或上一個索引數據。 –
更新了帖子,提供更多信息 – user4938361