Assume there's code for an iphone project that is :
IBOutlet UITextField* numberDisplay;
@property (strong,nonatomic) IBOutlet UITextField *numberDisplay;
in implementation file and
@synthesize numberDisplay;
in implementation file. Also in implementation is
-(IBAction)numberClicked:(id)sender {
UIButton *buttonPressed = (UIButton *)sender;
int val = buttonPressed.tag;
if ( [numberDisplay.text compare:@"0"] == 0 ) {
numberDisplay.text =[NSString stringWithFormat:@"%d", val ];
} else {
numberDisplay.text = [NSString
stringWithFormat:@"%@%d", numberDisplay.text, val ];
}
}
When I run the app there is no display shown in the UITextfield, even though the connections were made with IB and is proven to be made by viewing the inspector. Even as a test if I add the lines
numberDisplay.text = @"a";
NSLog(@"the value is %@",numberDisplay.text);
NSLog(@"the value is %@",numberDisplay);
I get " the value is (null) in both cases.Any ideas.
Can someone please tell me what is wrong with these two lines?. Thank you.
Thanks to all. I started from scratch and now all works. Looks like I had a mislabeled file.
numberDisplay
variable instead of it'stext
property. I do suspect that somewhere else you haven't initialized your text field; as you can't assign a variable to a null object you get null in return. – TriableUITextField
is not connected correctly, and this is likely true, but you should test for that. That can be done by adding a third line:NSLog(@"the text field is %@",numberDisplay);
– Warila