Question

Okay, so I'm trying to make this action change a user-editable textfield if the textfield is empty. This is the code i'm using right now, but it won't work:

if ([textField.text isEqualToString:[NSString stringWithFormat:@""]]) {
    [o1 setText:[NSString stringWithFormat:@"1"]];

Anybody know why? I did this as well:

UITextField *textField;

Is that necessary?

UPDATE: I just realized I should have put this in here earlier, but it's for ios, not mac. Sorry!

Was it helpful?

Solution

Your code is somewhat convoluted - just test like so:

if ([myTextField length] == 0) myTextField.text = @"1";

You need to declare myTextField in the interface like so:

IBOutlet UITextField *myTextField;

then link it in IB. You could make it a property to simplify memory management.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top