lanhailvcao 2012-09-26 02:00 采纳率: 71.4%
浏览 7745
已采纳

在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的值?先谢过了

  • 写回答

3条回答 默认 最新

  • MrsSeven7 2012-09-26 03:54
    关注

    有一种方法,可以在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];  
     }  
    

    }
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog