연락처를 선택한 후 단일 셀만 다시로드하려는 경우 (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 개의 값을 인쇄합니다. 나는 이유를 모른다. 아래 이미지가 있습니다. reloadItems을 최적화하는 방법 UI
의
는디자인?
정말 도움이됩니다. 많은 감사합니다.
'cellForItemAtIndexPath' 메소드의 나머지 부분을 설명 할 수 있습니까? 당신은 인덱스 1에서 셀을 처리하는 것으로 나타났습니다 ... 반면에 분명히 19 개의 셀이 사용되었습니다. 나머지 방법은 무엇입니까? – murphguy
@murphguy, 그것은 단지 4 셀이었습니다. 그 특정 셀에 대해서는 그 안에'UICollectionView'가 있어야합니다. 질문을 업데이트했습니다. – Nizzam
그 안에는 당신의 도전이 있습니다. 접을 수있는 셀 애니메이션/처리는 다소 무겁습니다. 그래서 그것은에 달려 있습니다 : 당신은 세포 내에서 자동 레이아웃을 사용하고 있습니까? 셀의 내용은 동적입니까? 별도의 스레드를 통해 이미지를 비동기 적으로로드합니까? 이 세 가지 질문은 왜 앱이 뒤떨어져 있는지에 대한 질문에 대답해야합니다. – murphguy