私は画像のグリッドを表示するコレクションビューを持っています。それは、ユーザーが自分自身に電子メールを送るために3つまでの画像を選択することを可能にする。ユーザーがセル(イメージ)をタップすると、黄色にハイライトされ、ファイル名が配列に追加されます。再度タップすると、選択が解除され、ハイライトが削除され、イメージがアレイから削除されます。UIコレクションビューで選択したハイライト表示されたセルを消去する方法
ユーザーが電子メールを送信すると、MFMailComposeResultデリゲートを使用して配列からアイテムを削除しますが、セルから黄色のハイライトを削除する方法はわかりません。誰かが助けられるかもしれないと願っています。感謝します。
私はdidSelectItemAtとdidDelectlectItemAt関数でイメージのファイル名を追加します。電子メールがどのようにクリアするために、デリゲート
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
if result == MFMailComposeResult.sent {
print("emailed Photos")
self.selectedFileNames.removeAll()
self.fullSizeSharableImages.removeAll()
}
}
任意のアイデアを使用してコードをここに送られているしたら
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let fileName = filenames[indexPath.item]
selectedFileNames.append(fileName)
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let fileName = filenames[indexPath.item]
if let index = selectedFileNames.index(of: fileName) {
selectedFileNames.remove(at: index)
}
}
と私は私のUICollectionViewCellクラス
override var isSelected: Bool {
didSet {
self.layer.borderWidth = 3.0
self.layer.borderColor = isSelected ? UIColor.yellow.cgColor : UIColor.clear.cgColor
}
}
で細胞を強調していますハイライトされたセル?
は完璧に機能しました。ありがとう! –