聚焦一个NSTextField [英] focus a NSTextField

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

问题描述

我有一个NSTextField,我想设置其内容,如果我klick一个按钮,而不是设置光标在这个文本字段在文本的结尾,所以如果有人klick按钮,他可以开始输入。 >

到现在为止,我使用[NSTextField selectText]它选择这个文本字段,但它选择整个文本,所以如果有人刚开始输入他会丢失文本字段中的所有文本。

解决方案

确定我现在找到了:)

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

,在RubyCocoa中是:

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


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 could just begin to type.

Until now I use [NSTextField selectText] it selects this textfield but it selects the whole text so if someone just begins to type he'd lose all the text which alread is in the textfield.

解决方案

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

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

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