i have nstableview
1 column. print row number of row user has clicked on. not sure should start this. there method this?
you can use selectedrowindexes
property tableview in tableviewselectiondidchange
method in nstableview delegate.
in example, tableview allows multiple selection.
swift 3
func tableviewselectiondidchange(_ notification: notification) { if let mytable = notification.object as? nstableview { // create [int] array index set let selected = mytable.selectedrowindexes.map { int($0) } print(selected) } }
swift 2
func tableviewselectiondidchange(notification: nsnotification) { var myselectedrows = [int]() let mytableviewfromnotification = notification.object as! nstableview let indexes = mytableviewfromnotification.selectedrowindexes // iterate on indexes using `.indexgreaterthanindex` var index = indexes.firstindex while index != nsnotfound { myselectedrows.append(index) index = indexes.indexgreaterthanindex(index) } print(myselectedrows) }
Comments
Post a Comment