所以我得到了此代码,在该代码中,我希望能够点击已创建的单元格,然后为其设置标题。如果再次点击它,我希望选择该单元格(将在此处点击更多单元格),然后再将其数据提交给警报,然后从应用程序中的持久化模型列表中进行选择。有没有简单的方法可以做到这一点?
如图所示:
默认情况下,“提交”按钮是禁用的,但是选中项目后,将启用该按钮以显示此警报,如前所述。
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
}
}
答案 0 :(得分:0)
写一个检查..如果image.label != "tap to edit"
然后在该单元格上显示选定的图像,并将该索引路径放入数组中..与其他单元格一样..当用户点击Submit ...得到所有从该数组索引并执行操作?