在do-while循环期间更改标签

时间:2011-08-17 10:35:40

标签: objective-c

所以我有一个循环XML文档的方法。该文档得到了许多答案值,这些答案值正在被提取并以UISegmentedControls的形式打印在屏幕上。 我现在得到的代码是:

- (void) traverseElement:(TBXMLElement *)element {
static CGFloat y = 300.0f;
static CGFloat dynamicHeight = 400.0f;
static int segmentId = 1;
    do {

    if([[TBXML elementName:element] isEqualToString:@"wcqAnswerValues"]) {

        NSString *segmentItemsStr = [TBXML textForElement:element];
        NSArray *segmentItemsArray = [segmentItemsStr componentsSeparatedByString:@";"];

        answer = [[UISegmentedControl alloc] initWithItems:segmentItemsArray];            
        answer.frame = CGRectMake(50, y, 400, 40);
        [answer addTarget:self action:@selector(textpopup:) forControlEvents:UIControlEventValueChanged];

        answer.segmentedControlStyle = UISegmentedControlStyleBar;
        answer.tag = segmentId;
        [scrollView addSubview:answer];

        scrollView.contentSize = CGSizeMake(768, dynamicHeight);

        [formulierText removeFromSuperview];

        [answer release];
        y += 40.0f;
        dynamicHeight += 40.0f;
        segmentId++;
    }

if ([[TBXML elementName:element] isEqualToString:@"formdata"]) {

        y = 300.0f;
        dynamicHeight = 400.0f;
        segmentId = 1;
    }

    // if the element has child elements, process them
    if (element->firstChild) 
        [self traverseElement:element->firstChild];

    // Obtain next sibling element
} while ((element = element->nextSibling));

}

-(void)textpopup:(UISegmentedControl *)sender {

        if (sender.tag == 1) {
        // if the tag of the sender is 1, then do something.
        }

}

我想要实现的目标是:

屏幕上打印的每个UISegmentedControl必须具有唯一的编号或ID,以便我可以单独为其分配操作。实现这一目标的最佳方法是什么?

修改 固定它。我会更新我的代码。

0 个答案:

没有答案