Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField settext not working

This is frustrating the hell out of me. I am a beginner programmer and cannot figure out why the text is not being changed.

Here is my method which is supposed to set the text of a UITextField:

-(void)updateDays:(NSInteger)days
{
    NSString* daysString = [[NSString alloc] initWithFormat:@"%d", days];
    [daysTextField setText:daysString];
    [daysString release];
}

For whatever reason nothing is happening.

Help appreaciated!

like image 665
Sean Wentz Avatar asked Dec 27 '22 20:12

Sean Wentz


2 Answers

Anytime you have a frustration along the lines of "why isn't this line working", use the debugger or just add an NSLog before it to print out the relevant data:

NSLog(@"updateDays: %@ %@ <= %@", daysTextField, daysTextField.text, daysString);

Then you know the line (a) is getting executed, (b) the variables are the ones you think they are, and (c) the values are reasonable.

like image 145
mackworth Avatar answered Jan 13 '23 18:01

mackworth


I have experienced this several times, but I think all of them was reasoned by that the UITextField was not initialized at that point.

Set a breakpoint and use debugger to make sure that your UITextField is not nil. You should also check the connection between the .xib file and your code.

like image 20
Yunus Nedim Mehel Avatar answered Jan 13 '23 18:01

Yunus Nedim Mehel