title: Changing the tags during do-while loop
body: <p>So i got a method to loop through an XML document. The document got a number of answervalues which are being extracted and are printed on the screen in the form of UISegmentedControls.
  The code i got right now is:</p>
  
  <pre><code>- (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-&gt;firstChild) 
          [self traverseElement:element-&gt;firstChild];
  
      // Obtain next sibling element
  } while ((element = element-&gt;nextSibling));
  
  }
  
  -(void)textpopup:(UISegmentedControl *)sender {
  
          if (sender.tag == 1) {
          // if the tag of the sender is 1, then do something.
          }
  
  }
  </code></pre>
  
  <p>What i want to achieve is this:</p>
  
  <p>Each UISegmentedControl that is being printed on the screen has to have a unique number or id so i can separately assign actions to them. What is the best way to achieve this?</p>
  
  <p><strong>EDIT:</strong>
  Fixed it. I will update my code.</p>