Editable NSTextField in NSTableView

夙愿已清 提交于 2021-02-09 02:44:49

问题


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) If I move the mouse over the editable NSTextField, the cursor don't change to the IBeamCursor (the edit cursor).

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.


回答1:


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

NSTableView - select row and respond to mouse events immediately

You have to subclass NSTableView. My swift code:

class TableViewEditing: NSTableView {

    ...

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

EDIT:

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.



来源:https://stackoverflow.com/questions/29986224/editable-nstextfield-in-nstableview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!