在iphone的uiscrollview中动态添加uitextfield

在iphone的uiscrollview中动态添加uitextfield,iphone,Iphone,我有一个包含一些值的数组,我想为数组中的所有字符串对象动态创建文本字段,并将其添加到scrollview中。。如何操作..您可以使用以下内容填充UIScrollView: // NSArray *strings; // UIScrollView *scrollView; // NSMutableArray *textFields; self.textFields = [NSMutableArray array]; const CGFloat width = 320; const CGFloa

我有一个包含一些值的数组,我想为数组中的所有字符串对象动态创建文本字段,并将其添加到scrollview中。。如何操作..

您可以使用以下内容填充UIScrollView:

// NSArray *strings;
// UIScrollView *scrollView;
// NSMutableArray *textFields;

self.textFields = [NSMutableArray array];

const CGFloat width = 320;
const CGFloat height = 31;
const CGFloat margin = 0;
CGFloat y = 0;

for(NSString *string in strings) {
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, y, width, height)];
    textField.delegate = self;
    textField.text = string;

    [scrollView addSubview:textField];
    [textFields addObject:textField];
    [textField release];

    y += height + margin;
}

scrollView.contentSize = CGSizeMake(width, y - margin);
和处理更改方法中的字符串