gpt4 book ai didi

ios - didSelectItem 未被调用

转载 作者:搜寻专家 更新时间:2023-11-01 06:29:15 26 4
gpt4 key购买 nike

我的 didSelectItemAt 方法没有被调用,控制台也没有打印任何内容。我打开了用户交互,但仍然无法打印出任何内容。我不确定是我的自定义 PinterestStyle 布局导致了这个问题,还是我遗漏了什么。最终目标是进入显示所选单元格配置文件页面的详细 View Controller 。我将使用 prepareForSegue 来做到这一点,但是我什至无法让它在点击时打印出单元格的名称。

class PagesCollectionViewController: UICollectionViewController, firebaseHelperDelegate {

var storageRef: StorageReference!{
return Storage.storage().reference()
}
var usersList = [String]()
var authService : FirebaseHelper!
var userArray : [Users] = []
var images: [UIImage] = []

var names: [String] = []

override func viewWillAppear(_ animated: Bool) {

if Global.Location != "" && Global.Location != nil
{
usersList = Global.usersListSent
print(usersList)
self.authService.ListOfUserByLocation(locationName: Global.Location, type: .ListByLocation)
}
}

override func viewDidLoad() {
self.collectionView?.allowsSelection = true
self.collectionView?.isUserInteractionEnabled = true
super.viewDidLoad()
self.authService = FirebaseHelper(viewController: self)
self.authService.delegate = self
setupCollectionViewInsets()
setupLayout()
}

private func setupCollectionViewInsets() {
collectionView!.backgroundColor = .white
collectionView!.contentInset = UIEdgeInsets(
top: 20,
left: 5,
bottom: 49,
right: 5
)
}

private func setupLayout() {
let layout: PinterestLayout = {
if let layout = collectionViewLayout as? PinterestLayout {
return layout
}
let layout = PinterestLayout()

collectionView?.collectionViewLayout = layout

return layout
}()
layout.delegate = self
layout.cellPadding = 5
layout.numberOfColumns = 2
}

func firebaseCallCompleted(data: AnyObject?, isSuccess: Bool, error: Error?, type: FirebaseCallType) {
if(type == .ListByLocation) {

if(isSuccess) {
self.userArray.removeAll()
self.images.removeAll()
self.images.removeAll()

if(data != nil) {

let dataDict = data as! NSDictionary
let keyArray = dataDict.allKeys

for i in 0 ..< keyArray.count {

var dict = NSDictionary()
dict = dataDict.object(forKey: keyArray[i]) as! NSDictionary
self.userArray.append(Users.init(data: dict))
}
}

self.collectionView?.reloadData()

}
else {
print(error?.localizedDescription)
SVProgressHUD.dismiss()
}
}

}
}
extension PagesCollectionViewController {
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return userArray.count
}

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(userArray[indexPath.row].name)
}



override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: "PagesCollectionViewCell",
for: indexPath) as! PagesCollectionViewCell

cell.nameLabel.text = userArray[indexPath.row].name

if let imageOld = URL(string: userArray[indexPath.row].photoURL){

cell.photo.sd_setImage(
with: imageOld,
placeholderImage: nil,
options: [.continueInBackground, .progressiveDownload]
)

}

return cell
}

}


extension PagesCollectionViewController : PinterestLayoutDelegate {

func collectionView(collectionView: UICollectionView,
heightForImageAtIndexPath indexPath: IndexPath,
withWidth: CGFloat) -> CGFloat {
var image: UIImage?

let url = URL(string: userArray[indexPath.row].photoURL)
let data = try? Data(contentsOf: url!)
image = UIImage(data: data!)

return (image?.height(forWidth: withWidth))!
}
func collectionView(collectionView: UICollectionView,
heightForAnnotationAtIndexPath indexPath: IndexPath,
withWidth: CGFloat) -> CGFloat {
return 30
}
}

最佳答案

检查 2 个条件:-

  • 确保您已将委托(delegate)设置为 UICollectionView
  • 确保 PageCollectionCell 中的内容类似于未启用用户交互的图像。如果启用图像用户交互,则不会调用 didSelectItemAt。

关于ios - didSelectItem 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49621476/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com