ユーザーが連絡先を選択した後で、単一のセルのみを再ロードしたい(method didSelect contact)
セル内のアイテムの数が増えると、プロセスが遅くなります。私もDispatchQueue.main.async { code }
に実装しようとしていますが、ロードにはまだ時間がかかります。Swift - UICollectionView reloadItemsが長すぎる
cellForItemAtとnoOfItemInSection(AddCell) - 総細胞4
var indexPaths = [IndexPath]()
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
indexPaths.append(indexPath)
if indexPath.item == 1 {
let addCell = collectionView.dequeueReusableCell(withReuseIdentifier: CellId, for: indexPath) as! AddCell
addCell.btnAdd.addTarget(self, action: #selector(handleOpenContact), for: .touchUpInside)
addCell.invitees = invitees
return addCell
}
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
cellForItemAtとnoOfItemInSection(SubAddCell)
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: subAddId, for: indexPath) as! SubAddCell
cell.delegate = self
cell.invitee = invitees[indexPath.item]
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return invitees.count
}
didSelect(ContactPicker)
func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
let invitee = Invitee()
invitee.name = contact.givenName
if contact.isKeyAvailable(CNContactPhoneNumbersKey) {
for phoneNumber: CNLabeledValue in contact.phoneNumbers {
let a = phoneNumber.value
print("\(a.stringValue)")
invitee.phoneNo = a.stringValue
}
}
self.invitees.append(invitee)
for index in self.indexPaths {
if index == [0, 0] {
print(index)
self.collectionView?.reloadItems(at: [index])
}
}
}
メソッドでindexPaths
の値を取得しています。参加者に5つのアイテムが含まれている場合、print(index)
は19の値を出力します。どうしてか分かりません。以下はイメージです。
UI
reloadItemsを最適化する方法のデザイン?
本当にありがとうございます。どうもありがとう。
あなたは 'cellForItemAtIndexPath'メソッドの残りの部分を記述できますか?あなたはインデックス1のセルを扱うことを示しているにすぎませんが、明らかに19のセルが使用されています。残りの方法は何ですか? – murphguy
@murphguy、それはわずか4セルでした。その特定のセルには、その内部に 'UICollectionView'があります。私は質問を更新しました。 – Nizzam
あなたの挑戦はうそです。折りたたみ可能なセルのアニメーション/処理はかなり重いです。したがって、それは依存しています:セル内でオートレイアウトを使用するかどうかセルダイナミックの内容ですか?別のスレッドを使って画像を非同期的に読み込んでいますか?これらの3つの質問は、あなたのアプリが遅れている理由についてのあなたの質問に答えるべきです。 – murphguy