我有一個帶有自定義單元格的 tableView,我的目標是能夠單擊一個并列印當前行的編號。
現在當我點擊一個單元格時不會發生,我不明白為什么。
This is the code:
//MARK: - UITableDataSource
extension ChannelViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return groupResult.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let group = groupResult[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: K.cellContactNibName, for: indexPath) as! ContactCell
cell.usernameLabel.text = group.name
cell.messageLabel.text = group.recentMessage
let storage = Storage.storage()
let storageRef = storage.reference()
// Reference to an image file in Firebase Storage
let reference = storageRef.child("imagesFolder/\(group.image)")
// UIImageView in your ViewController
let imageView: UIImageView = cell.uImage
// Placeholder image
let placeholderImage = UIImage(named: "MeAvatar")
// Load the image using SDWebImage
imageView.sd_setImage(with: reference, placeholderImage: placeholderImage)
cell.uImage.image = imageView.image
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("You selected cell #\(indexPath.row)!")
}
}
正如您在螢屏中看到的那樣,啟用了單一選擇:

uj5u.com熱心網友回復:
改成
extension ChannelViewController: UITableViewDataSource, UITableViewDelegate
或將該方法移動到另一個符合的擴展中UITableViewDelegate
另外,請記住將 tableView 的委托設定為ChannelViewController
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/529563.html
標籤:迅速表视图
上一篇:APIResponse的SwiftUIJSON解碼器回應為0
下一篇:可本地化的字串插值不能按預期作業
