0
votes

I created NSTextfield programmatically:

func createText(point:NSPoint) {
        let txtFld = AnnotationTextField(frame: NSMakeRect(point.x, point.y, 360,40))
        txtFld.isEnabled = true
        txtFld.delegate = self
        self.contentView.addSubview(txtFld)
        txtFields.append(txtFld)

        txtFld.becomeFirstResponder()
    }

But when I click on another field or hit Enter key, my string not saving.

enter image description here

1
From the docmentation of becomeFirstResponder: "Use the NSWindow makeFirstResponder(_:) method, not this method, to make an object the first responder. Never invoke this method directly.". - Willeke
Which methods did you override in AnnotationTextField? Where does "Enter your text here" come from? What happens when you use a NSTextfield? - Willeke

1 Answers

0
votes

I set stringValue in draw method. That was my fault