NSTableView中的可编辑NSTextField [英] Editable NSTextField in NSTableView

查看:71
本文介绍了NSTableView中的可编辑NSTextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于视图的NSTableView,在我的自定义和子类化视图中带有一些标签.标签之一应该是可编辑的,因此我将此NSTextField设置为可编辑.

I have a view based NSTableView with some labels in my customized and subclassed view. One of the label should be editable, so therefore I set this NSTextField to editable.

但是现在我有两个问题,我无法解决:

But now I have two problems, I can't solve:

1)如果将鼠标移到可编辑的NSTextField上,则光标不会更改为 IBeamCursor (编辑光标).

1) If I move the mouse over the editable NSTextField, the cursor don't change to the IBeamCursor (the edit cursor).

2)我需要双击标签才能进行编辑.我想单击一下.我在stackoverflow上找到了针对此问题的一些解决方案,最好的解决方法是覆盖 acceptsFirstResponder 以始终返回true,但是,然后单击NSTextField会选择整个文本,而不是将光标置于被单击的位置位置.

2) I need to double click at the label, to be able to edit. I want to have a single click. I found some solutions for this problem here at stackoverflow, the best one is to override the acceptsFirstResponder to return always true, but then, clicking at the NSTextField selects the whole text instead of placing the cursor at the clicked position.

推荐答案

抱歉,这是重复项.我发现了:

Sorry... this is a duplicate. I found this:

NSTableView-选择行并进行响应鼠标事件立即

您必须继承 NSTableView .我的快捷代码:

You have to subclass NSTableView. My swift code:

class TableViewEditing: NSTableView {

    ...

    override func validateProposedFirstResponder(responder: NSResponder, forEvent event: NSEvent?) -> Bool {
        return true
    }
}

编辑:

一个缺点:有时进入编辑模式,似乎只是很快选择和取消选择了文本.但是您可以看到,这是一个可可问题,例如在Apple提醒应用中是相同的.

Just one disadvantage: Sometimes entering the edit mode, it seems that the text is just shortly selected and deselected. But you can see, that this is a cocoa problem, it's the same for example in Apple reminders app.

这篇关于NSTableView中的可编辑NSTextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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