Reset NSTextField's text to empty string — setText: doesn't work

徘徊边缘 提交于 2019-12-02 08:01:42

问题


I have an NSTextField, and I need a button to reset the text of the field. How would I do that? I have been trying this:

[textBox setText:@""];
textbox.text = @"";

That does not work, but I have researched, and found nothing on how to set the text, only how to get the text.


回答1:


If it is OSX and NSTextField then use :

[textBox setStringValue:@""];



回答2:


Try this code:

theLabel.text = @"this is some text";
[self.view addSubView:theLabel];

Here, the label is the text field.



来源:https://stackoverflow.com/questions/14541619/reset-nstextfields-text-to-empty-string-settext-doesnt-work

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