I’m working on an app in which I need to scan through a string to populate some UITextViews. Basically the data is like this:
Time Period: 10am-12pm
Temperature: 45F
Wind: 123 degrees @ 5mph
Time Period: 1am-3pm
Temperature: 53F
Wind: 133 degrees @ 2mph
Time Period: 4am-5pm
Temperature: 50F
Wind: 110 degrees @ 7mph
The problem is that there is not a set number of time periods that are available at any given time. So I just have to loop through until I reach the end. Is there a way to create a textview inside a loop?
UITextView *textField1 = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
UITextView *textField2 = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
UITextView *textField3 = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
.....
So could I create the textfields at runtime until it reaches the end of the string or would I have to create the max number that it could possibly need then just use them if needed?
Thanks,
Andrew Boos
Sure you can.
First divide your data string using either [NSString componentsSeparatedByString] or [NSString componentsSeparatedByCharactersInSet] to get an NSArray of substrings.
//disclaimer: written this on the go, may contain some spelling mistakes etc, but should be enough to get you going.