怎麼在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];
}
}
}