开发者

dynamically add uitextfield in the uiscrollview in iphone

开发者 https://www.devze.com 2022-12-31 07:17 出处:网络
i have an arra开发者_JAVA百科y of some values and i want to dynamically create textfields for all the string objects inside the array and add it to the scrollview.. how to do it..You can populate the

i have an arra开发者_JAVA百科y of some values and i want to dynamically create textfields for all the string objects inside the array and add it to the scrollview.. how to do it..


You can populate the UIScrollView using something like this:

// 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);

and handle changing the strings in the UITextFieldDelegate methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消