Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Cocoa/Interface Builder, how to clear text in textfield after button click

I am making a simple Twitter update application using MGTwitterEngine

And I can't seem to get the TextField in Interface Builder to clear the text after they click the "update" button. Is there an easy method that I could do this with or something in Interface Builder?

Thanks a lot!

like image 879
Patrick C Avatar asked Mar 31 '09 16:03

Patrick C


3 Answers

IBOutlet NSTextField *textField;

[textField setStringValue:@""];
[textField display];
like image 68
andi Avatar answered Nov 19 '22 18:11

andi


I think you also need to define a IBAction method like:

- (IBAction) clearText:(id) sender {
    [textField setStringValue:@""];
    [textField display];
}

You can now assign a button event (e.g. button down) to this action.

like image 5
Koraktor Avatar answered Nov 19 '22 20:11

Koraktor


Be aware that it probably isn't when the button is pressed that the NSTextField is cleared, but when the tweet is uploaded.

Else you risk losing the tweet if it couldn't be sent for some reason.

[Not a solution to the direct question, but a solution to follow-up problem...]

like image 4
Matthew Schinckel Avatar answered Nov 19 '22 20:11

Matthew Schinckel