简体   繁体   English

以编程方式创建的UItextfield,以后如何获取文本?

[英]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.

相关问题 以编程方式创建的UItextfield,稍后如何在Swift中获取文本? - Created UItextfield programmatically, how to get text later in Swift? 如何获取在uiTableView中以编程方式创建的uiTextField的值? - How to get value of uiTextField created programmatically in a uiTableView? 以编程方式创建的 UITextField 未加载文本 IOS swift - Programmatically Created UITextField not loading text IOS swift 无法将以编程方式创建的UITextField文本设置为UIPickerView值 - Can't set programmatically created UITextField text to UIPickerView value 如何在循环中以编程方式更新UITextField中的文本 - How to update text in a UITextField programmatically in a loop 如何检查在UIAlertController中创建的UITextField的文本? - How to check UITextField's text that created in UIAlertController? 如何从动态创建的UITextField中获取文本而无需触摸或点击文本字段(禁用用户交互)? - How to get text from dynamically created UITextField without touching or tapping the text field (disabled user interaction)? 如何获取UItextfield的文本进行更新? - How to get the text of a UItextfield to update? 如果在UITableViewCell内以编程方式创建UITextField,如何辞职第一响应者? - How to resign first responder if UITextField is programmatically created inside a UITableViewCell? 如何按方向更改在以编程方式创建的滚动视图中调整以编程方式创建的UILabel,UITextView,UITextfield的大小 - How to resize the programmatically created UILabel,UITextView,UITextfield in programmatically created scroll view as per orientation change
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM