Reputation: 847
Inside the .h:
@interface MyController : UIViewController<UITextFieldDelegate> {
IBOutlet UITextField *phonenum;
IBOutlet UITextField *email;
}
@property (nonatomic, retain) UITextField *phonenum;
@property (nonatomic, retain) UITextField *email;
-(IBAction) btnClicked: (id) sender;
@end
Inside the .m:
-(IBAction) btnClicked: (id) sender{
NSString *str = [[NSString alloc]init];
NSLog(@"str=%@",str); //this contains valid value
email.text=str; /// does not set the value
[[self email] setText: str]; // does not set the value
}
What am i doing wrong where it does not set the UITextField value using the variable str that is NSString? Is this some kind of Inteface Builder setting? I have delegate link to file owner.
Upvotes: 0
Views: 1708
Reputation: 12949
Maybe you forgot to connect your outlets with the interface in Interface Builder
If you don't know how to do that, please see :
http://developer.apple.com/library/mac/#recipes/xcode_help-interface_builder/CreatingOutlet.html
Upvotes: 0
Reputation: 455
It seems that str is nil, so nothing happens. And your 2 last lines do the same thing. You should write
NSString *str = email.text;
And then do something with str, like
user.email = str;
or directly
user.email = email.text
if you want to update a user email with the text in your UITextField.
Upvotes: 2