程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-在IBAction中如何讀取UITextField的值?

ios-在IBAction中如何讀取UITextField的值?

編輯:編程綜合問答
在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的值?先謝過了

最佳回答:


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

}
}

lanhailvcao
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved