加载视图时,我以编程方式创建了一个 uitextfield。但是,如果在加载后按下按钮,我如何在以后的 void 中从该 uitextfield 获取文本?
-(void)viewDidLoad {
UITextField *fldcard= [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 293, 25)];
fldcard.placeholder = @"card";
fldcard.keyboardType = UIKeyboardTypeNumberPad;
[fldcard setBackgroundColor:[UIColor colorWithRed:0.22 green:0.53 blue:0.23 alpha:1.0]];
[fldcard.layer setCornerRadius:5.0f];
[fldcard.layer setMasksToBounds:YES];
[self.view addSubview:fldcard];
[fldcard release];
}
-(void)myAction:(id)sender {
[self.view endEditing:YES];
NSLog(@"fldcard %@", fldcard.text);
}