私はNSTableView
1つの列を持っています。ユーザーがクリックした行の行番号を出力したいと思います。どこから始めるべきかわかりません。これには方法がありますか?
4988 次
2 に答える
16
NSTableView デリゲートselectedRowIndexes
のメソッドで tableView のプロパティを使用できます。tableViewSelectionDidChange
この例では、tableView で複数選択が可能です。
スイフト3
func tableViewSelectionDidChange(_ notification: Notification) {
if let myTable = notification.object as? NSTableView {
// we create an [Int] array from the index set
let selected = myTable.selectedRowIndexes.map { Int($0) }
print(selected)
}
}
スイフト2
func tableViewSelectionDidChange(notification: NSNotification) {
var mySelectedRows = [Int]()
let myTableViewFromNotification = notification.object as! NSTableView
let indexes = myTableViewFromNotification.selectedRowIndexes
// we iterate over the indexes using `.indexGreaterThanIndex`
var index = indexes.firstIndex
while index != NSNotFound {
mySelectedRows.append(index)
index = indexes.indexGreaterThanIndex(index)
}
print(mySelectedRows)
}
于 2015-03-22T21:27:52.060 に答える
0
使用する-selectedRowIndexes
dataSource
次に、これらのインデックスを使用して、 (通常は配列)からデータを取得できます。
于 2015-03-22T18:42:40.020 に答える