How do i increment during a Do-While loop?
I have the following code:
do {
if ([[TBXML elementName:element] isEqualToString:@"wcqQuestionText"]) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];
label.text = [TBXML textForElement:element];
[scrollView addSubview:label];
[label release];
[formulierText removeFromSuperview];
开发者_如何学C}
// if the element has child elements, process them
if (element->firstChild)
[self traverseElement:element->firstChild];
// Obtain next sibling element
} while ((element = element->nextSibling));
Each time a label has been written, i want the next label to be positioned under the label that has just been created. How do i do this?
Create float variable to track y position of label's frame and increase it each time label is added (you'll also need to adjust scroll's contentSize if all labels do not fit its frame):
static CGFloat y = 100.0f;
do {
if ([[TBXML elementName:element] isEqualToString:@"wcqQuestionText"]) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, y, 200, 100)];
label.text = [TBXML textForElement:element];
[scrollView addSubview:label];
[label release];
[formulierText removeFromSuperview];
y += 100.0f;
}
// if the element has child elements, process them
if (element->firstChild)
[self traverseElement:element->firstChild];
// Obtain next sibling element
} while ((element = element->nextSibling));
P.S. Have you considered using standard UITableView instead of self-tailored UIScrollView?
精彩评论