我有一个 NSTableView ,我想获取单元格中存在的值。我只有一列,所以我只需要行号
我可以使用这个[tableView selectedRow] - 但是我应该把它放在哪里,我想把它放在一个在选择任何行时调用的方法中。
-(void)tableViewSelectionDidChange:(NSNotification *)notification{
NSLog(@"%d",[tableViewController selectedRow]);
}
上述方法也不起作用,我收到错误 -[NSScrollView selectedRow]:无法识别的选择器发送到实例 0x100438ef0]
我想要类似 iPhone 表格 View 中可用的方法 -
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
最佳答案
什么是tableViewController
对象?只有 NSTableView
实例响应 selectedRow
。您可以从 notification
的对象属性获取当前 TableView (发送通知的 TableView ):
目标-C:
-(void)tableViewSelectionDidChange:(NSNotification *)notification{
NSLog(@"%d",[[notification object] selectedRow]);
}
swift :
func tableViewSelectionDidChange(notification: NSNotification) {
let table = notification.object as! NSTableView
print(table.selectedRow);
}
关于xcode - 在 Cocoa OS X 中选择 NSTableView 中的单元格时会调用哪个方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10796724/