UICollectionViewCell 将 indexpath.item 传递给列表
UICollectionViewCell pass indexpath.item to list
所以我得到了这段代码,我希望能够点击创建的单元格,然后为其设置标题。如果我再次点击它,我希望在我将它们的数据提交到警报之前选择该单元格(此处将点击更多单元格),我从应用程序中的持久模型列表中进行选择。有没有简单的方法可以做到这一点?
如图所示:
The submit-button is disabled by default, but when items are selected it is enabled to show this alert as described earlier.
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let image = images[indexPath.item]
if (image.label == "Tap to Edit") {
let alertController = UIAlertController(title: "Set image title", message: nil, preferredStyle: .alert)
alertController.addTextField()
alertController.addAction(UIAlertAction(title: "OK", style: .default) { [weak self, weak alertController] _ in
guard let newTitle = alertController?.textFields?[0].text else {
return
}
image.label = newTitle
self?.collectionView.reloadData()
})
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel))
present(alertController, animated: true)
} else {
// addToList
}
}
写一张支票..如果image.label != "tap to edit"
然后在该单元格上显示所选图像并将该索引路径放入数组中....其他单元格也是如此..当用户点击提交时...从该数组中获取所有索引并执行操作?
所以我得到了这段代码,我希望能够点击创建的单元格,然后为其设置标题。如果我再次点击它,我希望在我将它们的数据提交到警报之前选择该单元格(此处将点击更多单元格),我从应用程序中的持久模型列表中进行选择。有没有简单的方法可以做到这一点?
如图所示:
The submit-button is disabled by default, but when items are selected it is enabled to show this alert as described earlier.
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let image = images[indexPath.item]
if (image.label == "Tap to Edit") {
let alertController = UIAlertController(title: "Set image title", message: nil, preferredStyle: .alert)
alertController.addTextField()
alertController.addAction(UIAlertAction(title: "OK", style: .default) { [weak self, weak alertController] _ in
guard let newTitle = alertController?.textFields?[0].text else {
return
}
image.label = newTitle
self?.collectionView.reloadData()
})
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel))
present(alertController, animated: true)
} else {
// addToList
}
}
写一张支票..如果image.label != "tap to edit"
然后在该单元格上显示所选图像并将该索引路径放入数组中....其他单元格也是如此..当用户点击提交时...从该数组中获取所有索引并执行操作?