UICollectionView didSelectItemAt not responding?
trusbe opened this issue · 3 comments
Hello, I encountered a problem during use. I added UICollectionView to the pop-up view, but it cannot respond to
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
do you have any suggestions?
thank you very much.
Do you have a little more context? Have you connected the collection view to a delegate, if so, what's the delegate? Post a little more code and others might be able to help!
@Yonodactyl Hello, I'm very sorry, the following is the supplementary content.
This is the entrance, which can be loaded normally:
let vc = ATHFuncVC()
let uiConfiguration = PresentationUIConfiguration(cornerRadius: 16, backgroundStyle: .dimmed(alpha: 0.3), isTapBackgroundToDismissEnabled: true, corners: [.layerMaxXMaxYCorner,.layerMaxXMinYCorner,.layerMinXMaxYCorner,.layerMinXMinYCorner])
let size = PresentationSize(width: .fullscreen, height: .halfscreen)
let alignment = PresentationAlignment(vertical: .bottom, horizontal: .center)
let timing = PresentationTiming(duration: .medium, presentationCurve: .easeIn, dismissCurve: .easeOut)
let interactionConfiguration = InteractionConfiguration(presentingViewController: self, completionThreshold: 0.5, dragMode: .canvas)
let presentation = CoverPresentation(directionShow: .bottom,
directionDismiss: .bottom,
uiConfiguration: uiConfiguration,
size: size,
alignment: alignment,
marginGuards: .zero,
timing: timing,
spring: .none,
interactionConfiguration: interactionConfiguration)
animator = Animator(presentation:presentation)
animator?.prepare(presentedViewController: vc)
present(vc, animated: true, completion: nil)
This is a subview in ATHFuncVC:
let funcView = ATHFuncView()
funcView.getInfo { (row) in
logger("ATHFuncVC", sub: "funcView", info: "Index: \(row)")
}
self.view.addSubview(funcView)
There is a UICollectionView
in the ATHFuncView
view:
let layout = UICollectionViewFlowLayout.init()
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.backgroundColor = .clear
collectionView.dataSource = self
collectionView.delegate = self
collectionView.allowsSelection = false
collectionView.allowsMultipleSelection = false
collectionView.alwaysBounceVertical = false
collectionView.showsVerticalScrollIndicator = false
collectionView.register(ATHFuncCell.self, forCellWithReuseIdentifier: cellId1);
self.addSubview(collectionView)
// MARK: - UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
extension ATHFuncView: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let contentSize = (ScreenWidth-10*8)/4
return CGSize(width: contentSize, height: 80)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 8
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 8
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId1, for: indexPath) as! ATHFuncCell
switch indexPath.row {
case 0: cell.setInfo("home_func_loc", title: "Real-time location".localized())
case 1: cell.setInfo("home_func_fence", title: "Electronic fence".localized())
case 2: cell.setInfo("home_func_Leash", title: "Electronic traction".localized())
default: cell.setInfo("home_func_his", title: "History data".localized())
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
logger("ATHFuncView", sub: "didSelectItemAt", info: "Row:\(indexPath.row)")
// Will not respond here
if callBackInfo != nil {
callBackInfo!(indexPath.row)
}
}
}
I looked up the information on the Internet, and some people said that it might be a gesture conflict. How can I set it in Jelly to avoid this situation?
Thank you very much for replying.
😅 I found the problem and forgot when I turned it off.
collectionView.allowsSelection = false