【发布时间】:2020-02-19 03:15:26
【问题描述】:
我正在使用下面的代码来完成在分段控制中选择单元格以执行 segue 并相应地传递信息时完成的操作,但它没有按预期执行,它在被点击的单元格上没有做任何事情。
下面的代码是通过扩展实现的
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) -> UITableViewCell {
print("hello1")
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! MyWsPostCell
switch segmentControl.selectedSegmentIndex{
case 0:
print("hello2")
cell.section1 = section1list[indexPath.row]
cell.commentbutton.tag = indexPath.row
cell.commentbutton.addTarget(self, action: #selector(todetailview(_:)), for: .touchUpInside)
break
case 1:
print("hello4")
cell.section2 = section2list[indexPath.row]
cell.commentbutton.tag = indexPath.row
cell.commentbutton.addTarget(self, action: #selector(todetailview(_:)), for: .touchUpInside)
break
default:
break
}
return cell
}
函数调用
@objc func todetailview(_ sender: AnyObject) {
performSegue(withIdentifier: "myWtoDetail", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var vc = segue.destination as! DetailViewController
vc.infopassed = infokey
}
如果需要更多信息,请告诉我
【问题讨论】:
-
你把delegate设置成tableView了吗?
-
@AjinkyaSharma 是的,我已经这样做了,已经根据需要执行了一个 segue,这是关于必须点击单元格的第二个 segue
-
好的,首先你将目标添加到 didSelectRow 中的按钮。那不会调用 action 方法。
-
是否调用了 didSelectRow?
-
@AjinkyaSharma 如何确保 didSelectRow 被调用?抱歉,我正在学习 swift
标签: ios swift uitableview segue uisegmentedcontrol