Objective c 在do while循环期间更改标记

Objective c 在do while循环期间更改标记,objective-c,Objective C,所以我得到了一个循环遍历XML文档的方法。该文档获得了许多应答值,这些值正在被提取,并以UISegmentedControls的形式打印在屏幕上。 我现在得到的代码是: - (void) traverseElement:(TBXMLElement *)element { static CGFloat y = 300.0f; static CGFloat dynamicHeight = 400.0f; static int segmentId = 1; do { if([[TBX

所以我得到了一个循环遍历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,以便我可以分别为其分配操作。实现这一目标的最佳方式是什么

编辑:
修好了。我将更新我的代码。

您发布的代码无效。您的“do while”语句没有“do”。仔细检查项目中的内容。对不起,我遗漏了很多代码。因为它无关紧要。但我会更新我的代码!