UITextField setText failing to change text
The following method is being called, and the variable days has a valid value. When line 4 prints, the output is "TextField Text: (null). The address for daysTextField is 0x0 (uninstantiated?).
The IBOutlets are hooked up correctly as well as the property/synthesize.
This is real开发者_开发知识库ly frustrating me.
-(void)updateDays:(NSInteger)days
{
[daysTextField setText:[NSString stringWithFormat:@"%d", days]];
NSLog(@"TextField Text: %@", daysTextField.text);
}
Help extremely appreciated!
The most likely thing is that daysTextField
is nil. If this is an IBOutlet from Interface Builder make sure it is connect up correctly. Hope this helps.
You could try this:
-(void)updateDays:(NSInteger)days
{
NSString* s = [NSString stringWithFormat:@"%d", days];
NSAssert(s, @"string is nil");
NSAssert(daysTextField, @"daysTextField is nil");
[daysTextField setText:s];
NSLog(@"TextField Text: %@", daysTextField.text);
}
Your program will crash into the debugger on one or other of the asserts and you will have your answer. The string is very unlikely to be nil.
精彩评论