UITextField where are the values kept?
I created simple gui, with 3 UITextField
Added a button, when click submit, for the test I have printed the 3 text values... which I type in the text box of each field... what am I missing here? should I keep it to the disk of the mobile device before.. submit?
IOS version 5.0 beta
#import <UIKit/UIKit.h>
@interface CloudClientViewController : UIViewController
{
@private
UITextField *usernameData;
UITextField *passwordData;
UITextField *ngccData;
UIButton *submitButton;
}
@property (nonatomic,retain) IBOutlet UITextField *usernameData;
@property (nonatomic,retain) IBOutlet UITextField *passwordData;
@property (nonatomic,retain) IBOutlet UITextField *ngccData;
@property (nonatomic,retain) UIButton *submitButton;
-(IBAction)submitButton:(id)sender;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
/*
Allocting memory for the username password and the ngcc server
*/
usernameData = [[UITextField alloc]init];
passwordData = [[UITextField alloc]init];
ngccData = [[UITextField alloc]init];
}
-(IBAction)submitButton:(id)sender
{
NSLog(@"The value that was entered to usernameData is: %@",usernameData.text);
NSLog(@"The value that was entered to passwordData is: %@",passwordData.text);
NSLog(@"The value that was entered to ngccData is: %@",ngccData.text);
}
Now when the gui prompt, I am entering just test as a string in the UITextField field and click submit, I am expecting to see the test string as value, instead I see null.
Ideas?
GNU gdb 6.3.50-20050815 (Apple version gdb-1705) (Tue Jul 5 07:28:08 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 10248. 2011-07-27 16:52:56.235 CloudClient[10248:207] The value that was entered to usernameData is:开发者_Go百科 (null) 2011-07-27 16:52:56.237 CloudClient[10248:207] The value that was entered to passwordData is: (null) 2011-07-27 16:52:56.238 CloudClient[10248:207] The value that was entered to ngccData is: (null)
You define three IBOutlet properties suggesting that your text fields are to be loaded from a nib file when your view is loaded.
Once your view is loaded you create assign the ivars backing those properties to point to new text fields. This leaks any text fields you actually loaded from your nib. It also leaves you with properties which point to text fields which have not been added to your view and which are not visible.
You then enter text into one of the text fields in your view (loaded from your nib) and wonder why the entirely different text field you created in -viewDidLoad does not contain the text you entered.
精彩评论