gpt4 book ai didi

swift - 检测点击的tableView

转载 作者:行者123 更新时间:2023-11-30 12:35:05 25 4
gpt4 key购买 nike

无论选择如何,我都需要知道鼠标单击涉及的表格 View 。考虑一下

func tableViewSelectionDidChange(notification: NSNotification) {
self.selectedTableView = (notification.object as! NSTableView)
switch selectedTableView {
case oneTableView?:
print("one")
break
case twoTableView?:
print("two")
break
default:
print("wtf \(selectedTableView)")
}
}

表/ View “二”是“一”的详细信息。选择“一”中的一行会更改 TableView “二”的内容(标题 -> 详细信息)。但是,如果用户单击已选择的行,则不会收到通知,因为选择没有更改。基本上我只需要知道点击的最后一个表格 View /列。

mouseDown 方法是否更好(更困难),但我没有在 AppKit -> NSTableView -> NSTableView 中看到 Objective-C 或“UI”等效委托(delegate)方法用于列或行选择方法?

最佳答案

你应该做的是,在这个 UITableViewDelegate 函数中:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let tableOne = tableView as? TableOne {// do code here to other table}
else if let tableTwo = tableView as? TableTwo {//do code here to other table}
}

关于swift - 检测点击的tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42984997/

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