swift 3 检查按下按钮的行
swift 3 check the row where the button was pressed
我有一个带有自定义单元格的大纲视图。
一切正常,但我需要知道,如果一个按钮被按下,那个按钮在第几行。
我怎样才能得到这个行号?
您可以将按钮的操作连接到视图控制器(或任何关于大纲视图的知识)中的 IBAction
并在大纲视图上调用 row(for:)
:
@IBAction func buttonClicked(_ sender: NSButton) {
print("button row:", outlineView.row(for: sender))
}
直接来自文档:
This method is typically called in the action method for an NSButton
(or NSControl) to find out what row (and column) the action should be
performed on.
我有一个带有自定义单元格的大纲视图。 一切正常,但我需要知道,如果一个按钮被按下,那个按钮在第几行。
我怎样才能得到这个行号?
您可以将按钮的操作连接到视图控制器(或任何关于大纲视图的知识)中的 IBAction
并在大纲视图上调用 row(for:)
:
@IBAction func buttonClicked(_ sender: NSButton) {
print("button row:", outlineView.row(for: sender))
}
直接来自文档:
This method is typically called in the action method for an NSButton (or NSControl) to find out what row (and column) the action should be performed on.