gpt4 book ai didi

swift - 自定义单元格中的 didSelectRowAt 不执行任何操作

转载 作者:行者123 更新时间:2023-11-30 12:17:03 29 4
gpt4 key购买 nike

下面的代码应该从数组中调用用户名,并且用户能够点击所需的用户名。对该数组的调用成功,我可以看到用户名,但无法利用它。它甚至不打印“didSelectRowAt”。感谢你的帮助。谢谢。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath) as! MentionUserCell

cell.username!.text = autoComplete[indexPath.row]

return cell
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return autoComplete.count
}



func numberOfSections(in tableView: UITableView) -> Int
{
return 1
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{

let selectedCell: MentionUserCell = tableView.cellForRow(at: indexPath)! as! MentionUserCell
let selectedWord: String = selectedCell.username!.text! + " "
print("didSelectRowAt")
var string: NSString = NSString(string: self.commentTextView.text!)
string = string.replacingCharacters(in: otoCadang.sharedInstance.foundRange, with: selectedWord) as NSString

// change text field value
commentTextView.text = string as? String

// change cursor position
let positionOriginal = commentTextView.beginningOfDocument
if let cursorLocation: UITextPosition = self.commentTextView.position(from: positionOriginal, offset: otoCadang.sharedInstance.foundRange.location + selectedWord.characters.count)
{
self.commentTextView.selectedTextRange = self.commentTextView.textRange(from: cursorLocation, to: cursorLocation)
}



// remove suggestion
self.autoComplete.removeAll()
self.tableView.reloadData()
tableView.isHidden = true
}

最佳答案

检查 list

  1. tableview委托(delegate)设置正确
  2. tableview选择模式==无选择,则改为单选
  3. 函数名称正确 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  4. 您是否在此 View 上使用了任何点击手势?删除它。

关于swift - 自定义单元格中的 didSelectRowAt 不执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45295641/

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