[英]Created UItextfield programmatically, how to get text later?
I've created a uitextfield programmatically when the view is loaded. 加载视图时,我已经以编程方式创建了uitextfield。 If a button is pressed after it loads, though, how do I get the text from that uitextfield in a later 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);
}
In your .m file under: 在您的.m文件中:
@interface YourViewController ()
{
UITextField *fldcard;
}
@end
Then take out UITextField when you init fldcard. 然后在启动fldcard时取出UITextField。 You will be able to get that UITextField for any method in that class.
您将能够为该类中的任何方法获取该UITextField。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.