Gau*_*oni 7 xcode cocoa nstableview osx-snow-leopard
我有一个NSTableView,我想获得单元格中的值.我只有一列,所以我只需要行号
我可以使用这个[tableView selectedRow] - 但我把它放在哪里我想把它放在一个方法中,在选择任何行时调用它.
-(void)tableViewSelectionDidChange:(NSNotification *)notification{
NSLog(@"%d",[tableViewController selectedRow]);
}
Run Code Online (Sandbox Code Playgroud)
上面的方法也不起作用我收到错误 - [NSScrollView selectedRow]:无法识别的选择器发送到实例0x100438ef0]
我想要类似iPhone tableview中可用的方法 -
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
Run Code Online (Sandbox Code Playgroud)
Eim*_*tas 26
什么是tableViewController对象?只有NSTableView实例才会响应selectedRow.您可以从notification对象属性获取当前表视图(发送通知的视图):
Objective-C的:
-(void)tableViewSelectionDidChange:(NSNotification *)notification{
NSLog(@"%d",[[notification object] selectedRow]);
}
Run Code Online (Sandbox Code Playgroud)
迅速:
func tableViewSelectionDidChange(notification: NSNotification) {
let table = notification.object as! NSTableView
print(table.selectedRow);
}
Run Code Online (Sandbox Code Playgroud)