Xcode Swift.如何以编程方式在基于视图的NSTableView中选择单元格 [英] Xcode Swift. How to programmatically select Cell in view-based NSTableView

查看:171
本文介绍了Xcode Swift.如何以编程方式在基于视图的NSTableView中选择单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以单击一个单元格并编辑其内容.但是,除了单击/选择单元格外,还可以通过编程方式选择一个单元格-基本上使单元格焦点可供编辑.

I can click a cell and edit its contents. But, instead of click/selecting a cell is it possible to programmatically select a cell - basically give a cell focus ready for editing.

StackOverflow上有人在问有关UITableView的相同问题,给出的答案是:-

Somebody here on StackOverflow asked the same question about UITableView and the answer given was:-

let indexPath = NSIndexPath(forRow: 2, inSection: 0)
tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: .Middle)

selectRowAtIndexPath是否选择一个单元格?无论如何,我的NSTableView似乎都没有.selectRowAtIndexPath(...方法.)

Does selectRowAtIndexPath select a cell? In any case, my NSTableView doesn't appear to have a .selectRowAtIndexPath(... method anyway.

请为我提供一个资源,在这里我可以入门并自己解决其余的问题.

Please point me at a resource where I can get a start and figure the rest out for myself.

推荐答案

在此问题之前,我先用谷歌搜索了两天.但是现在几乎在发布问题后,我立即设法解决了这个问题. 实际上,它是如此简单,我不敢相信花费这么长时间就能弄清楚.

I'd googled this for two days solid before asking the question here. But now almost immediately after posting the question I managed to get it working. In fact it's so simple I can't believe it took so long to figure it out.

// Assuming we want to programmatically select Column 4, Row 5
myTableView?.editColumn(4, row: 5, withEvent: nil, select: true)

在旅行中,我发现数十个人问这个问题,但没有简单的答案.或者当tableView是基于视图"而不是基于单元格时,实际上可以与NSTableView而不是UITableView一起使用的答案.因此,希望我在这里发布此内容对其中一些人有所帮助.

On my travels I found dozens of people asking this question but no simple answers. Or answers that actually worked with NSTableView rather than UITableView and when tableView is 'view based' rather than cell based. So I hope me posting this here will help some of those people.

这篇关于Xcode Swift.如何以编程方式在基于视图的NSTableView中选择单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆