focus a NSTextField

后端 未结 5 2091
深忆病人
深忆病人 2020-12-08 08:55

I have a NSTextField and I want to set its content if I klick on a button and than set the cursor on this textfield at the end of the text so if someone klicks the button he

5条回答
  •  伪装坚强ぢ
    2020-12-08 09:00

    Ok I found it out now :)

    - (IBAction)focusInputField:(id)sender {
        [textField selectText:self];
        [[textField currentEditor] setSelectedRange:NSMakeRange([[textField stringValue] length], 0)];  
    }
    

    and in RubyCocoa it is:

    def select_input_field
        @input.selectText self
        range = OSX::NSRange.new(@input.stringValue.length, 0)
        @input.currentEditor.setSelectedRange range
    end
    

提交回复
热议问题