UICollectionView가 있으며 사용자가 셀에서 함수를 사용하도록 선택할 수 있습니다. 그래서 첫 번째 스크린 샷에서 선택한 것과 같이 첫 번째 셀을 설정해야합니다. 그러나 문제는 셀이 선택되고 사용자가 첫 번째 셀을 선택 취소하지 않는 다른 셀을 선택하려고 할 때입니다. 내가 선택한 테이블 항목을 재로드하려고했지만 viewdidload에서이 func를 실행하거나 실행하지 마십시오 LabelCollectionView.selectItem(at: IndexPath(row: 1, section: 0), animated: true, scrollPosition: .bottom)
첫 번째로드시 UICollectionView의 SelectItem로드
내가 무엇을 만들 수 있는지 알 수있는 누군가가 있습니까? 도움을 주셔서 감사합니다 :) 당신이 indexPath.row == indexPath.row
에 대한 검사와 함께 할 려
Here you see the Problem in the screenshot
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "StoryLabelCell", for: indexPath) as! StoryLabelCell
let labels = Labels[indexPath.row]
cell.backgroundColor = UIColor.lightGray
cell.layer.cornerRadius = 10
cell.Title.text = labels
if indexPath.row == 0 {
cell.backgroundColor = darkgrau
cell.layer.borderColor = black.cgColor
cell.layer.borderWidth = 2.0
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as! StoryLabelCell
if indexPath.row == indexPath.row {
cell.backgroundColor = darkgrau
cell.layer.borderColor = black.cgColor
cell.layer.borderWidth = 2.0
}
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as! StoryLabelCell
if indexPath.row == indexPath.row {
cell.backgroundColor = lightGray
cell.layer.borderWidth = 0
}
}
다른 셀을 {index path.row == index path.row} else {}에서 밝은 회색 (선택되지 않음)으로 설정했지만 사용하지 않으면 선택된 셀만 표시됩니다. 그래서 그것은 모두 실행하지만 문제는 내가 다른 셀을 선택 (첫 번째 셀이 선택됨)하고 멀리 가지 않고 두 개의 셀을 선택하려고 할 때입니다. 어쨌든 다른 셀을 탭하면 첫 번째 셀의 선택 (밝은 회색)을 변경해야합니다. –
예 어떻게 작동하는지, UI를 변경하려면 selected = true로 표시하고 다른 셀을 선택하면 false로 다시 설정해야합니다. 위의 코드를 사용 했습니까? – Santosh
예. 시도해 보았지만 실행하지 않았 으면 didSelectItemAt에 다른 방법이 있습니까? –