斯威夫特& NSTableView-只需选择一行 [英] Swift & NSTableView - Simply select a row

查看:86
本文介绍了斯威夫特& NSTableView-只需选择一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式在我的NSTableView中选择一行,只有一列.

I'd like to programatically select a row in my NSTableView, with just one column.

func selectColumnIndexes(_ indexes: NSIndexSet!,
    byExtendingSelection extend: Bool)

我一直在玩这个游戏,但是我不确定如何编写选择第2行".
我必须从连接到表视图"的@IBOutlet的变量开始吗?我必须以某种方式表明它与我的NSTableView有关.

I have been playing around with this, but I am not sure how to write "Select row #2".
Do I have to start with the variable connected to the @IBOutlet of my Table View? I have to indicate it is about my NSTableView somehow.

谢谢!

推荐答案

Swift 4解决方案

我创建了一个扩展程序,以使其变得更容易一些.另外,如果您在表格视图单元格上实施了点击操作,则也会对其进行调用

I created an extension to make a little easier to do this. Also if you implemented a click action on the table view cell this will invoke it as well

extension NSTableView {
    func selectRow(at index: Int) {
        selectRowIndexes(.init(integer: index), byExtendingSelection: false)
        if let action = action {
            perform(action)
        }
    }
}

/// USAGE:
NSTableView().selectRow(at: 0)

这篇关于斯威夫特& NSTableView-只需选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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