开发者社区> 问答> 正文

在IBAction中如何读取UITextField的值?

怎么在IBAction中读取UITextField的值?UITextField是通过编程创建的,所以不能在XCode设置@property和@synthesize。 我的UITextField生成文件如下:

for(i=0; i<[fieldName count]; i++)
{  
UITextField *name= [fieldName objectAtIndex:i];  
frame= CGRectMake(fromLeft, fromTop, totalWidth, totalHeight); 
name= [[[UITextField alloc] initWithFrame:frame] autorelease];        
name.borderStyle= UITextBorderStyleRoundedRect;   
name.returnKeyType= UIReturnKeyDone;  
//name.placeholder = [fieldName objectAtIndex:i];   \
name.autocapitalizationType= UITextAutocapitalizationTypeWords;       
name.adjustsFontSizeToFitWidth= TRUE;  
name.keyboardType= UIKeyboardTypeDefault;  
[name addTarget:self action:@selector(doneEditing:) 
forControlEvents:UIControlEventEditingDidEndOnExit];     
[scroller addSubview:name];   
fromTop= fromTop+ 40;
}

我想问的是,怎么实现点击按钮(IBAction)就能读取各个TextBox的值?

展开
收起
爵霸 2016-05-27 16:06:49 1881 0
1 条回答
写回答
取消 提交回答
  • 有一种方法,可以在UITextField中使用循环,继承self.view。把text添加给NSMutableArray。

     for (UITextField *field in self.view.subviews) {  
     if ([field isKindOfClass:[UITextField class]]) {  
     if ([[field text] length] > 0) {        
    [someMutableArray addObject:field.text];  
     }  
    }
     }
    2019-07-17 19:18:10
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载