NSTextField强制成为firstResponder删除文本

时间:2018-08-12 06:14:13

标签: swift xcode macos cocoa nstextfield

在自定义NSTableCellView上使用NSTextField。

当用户在单元格上的任意位置按下时,我希望NSTextField成为第一响应者。 当我这样做时,文本消失了,用户需要按任意键盘键才能使其返回,如何禁用此行为?

代码:

    override func mouseDown(with event: NSEvent) {
        super.mouseDown(with: event)
        if (event.clickCount == 2) {
            self.beginEditing()
        } else {
            self.endEditing()
        }
    }

    private func beginEditing() {
        self.lblTitle.isEditable = true
        self.window?.makeFirstResponder(self.lblTitle)
        self.lblTitle.backgroundColor = Colors.clear
        self.lblTitle.borderColor = Colors.clear
    }

    private func endEditing() {
        self.lblTitle.isEditable = false
        self.lblTitle.backgroundColor = Colors.red
    }

1 个答案:

答案 0 :(得分:0)

删除此行即可解决

<xarray.DataArray 'd_elev' (DS_UTCTime_40: 270240)>
dask.array<shape=(270240,), dtype=float64, chunksize=(270240,)>
Coordinates:
    lat      (DS_UTCTime_40) float64 dask.array<shape=(270240,), chunksize=(270240,)>
    lon      (DS_UTCTime_40) float64 dask.array<shape=(270240,), chunksize=(270240,)>
Dimensions without coordinates: DS_UTCTime_40
Attributes:
    units:          meters
    hertz:          40
    long_name:      Surface Elevation
    standard_name:  height_above_reference_ellipsoid
    description:    Surface elevation with respect to the ellipsoid at the sp...
    source:         Rel 34 GLAS Binary Data
    coordinates:    DS_UTCTime_40
    valid_min:      -500.0
    valid_max:      10000.0