i have an array 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..
A:
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.
Can Berk Güder
2010-05-25 11:43:24