开发者

Getting the value of textfields which are created during runtime

i am building a form when a button is pressed. When the button has been pressed, an ASIHTTPRequest to a server get send. This server is returning a XML document, which i am building a form of.

the method, which is building up a form looks like this:

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

    do {

    if ([[TBXML elementName:element] isEqualToString:@"wcqQuestionText"]) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(75, y, 200, 50)];
        label.text = [TBXML textForElement:element];
        [scrollView addSubview:label];
        scrollView.contentSize = CGSizeMake(768, dynamicHeight);
        [formulierText removeFromSuperview];
        [label release];
        y += 50.0f;
        dynamicHeight += 50.0f;

    }

    if([[TBXML elementName:element] isEqualToString:@"wcqAnswerValues"]) {
        NSString *segmentItemsStr = [TBXML textForElement:element];
        NSArray *segmentItemsArray = [segmentItemsStr componentsSeparatedByString:@";"];
        UISegmentedControl *answer = [[UISegmentedControl alloc] initWithItems:segmentItemsArray];            
        answer.frame = CGRec开发者_运维百科tMake(50, y, 400, 40);
        [answer addTarget:self action:@selector(textpopup:) forControlEvents:UIControlEventValueChanged];
        answer.segmentedControlStyle = UISegmentedControlStyleBar;
        [scrollView addSubview:answer];
        scrollView.contentSize = CGSizeMake(768, dynamicHeight);
        [formulierText removeFromSuperview];
        [answer release];
        y += 40.0f;
        dynamicHeight += 40.0f;
    }

    if([[TBXML elementName:element] isEqualToString:@"rayonfiliaal"]) {   
    NSString *rayonFiliaal = [TBXML textForElement:element];
    [stringsArray addObject:rayonFiliaal];

    }

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

    NSString *filiaalNaam = [TBXML textForElement:element];    
    [filiaalArray addObject:filiaalNaam];

    }       
    if ([[TBXML elementName:element] isEqualToString:@"formdata"]) {  
        y = 300.0f;
        dynamicHeight = 400.0f;
    }
    // if the element has child elements, process them
    if (element->firstChild) 
        [self traverseElement:element->firstChild];
    // Obtain next sibling element
} while ((element = element->nextSibling));
}

What i wanted to do is:

If an user fills in the form. I need to save it as a local XML file, with the values in it. What is the best way to achieve this?


You could just store those values in a plist.

This link should show you how to create a plist.

Property List Programming Guide

You can just read each of the values in the label by using this method [label text];

For the segmented control you would use the following method [answer titleForSegmentAtIndex:index];

These methods will return a NSString which you can store in a NSDictionary.

Once you have gotten those values, just create the NSDictionary object and call [dictionary writeToFile:pathToDirectory atomically:YES];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜