2011-08-17 8 views
0

ボタンを押したときにフォームを作成しています。ボタンが押されると、サーバーへのASIHTTPRequestが送信されます。このサーバーはXML文書を返しています。実行時に作成されるテキストフィールドの値を取得する

フォームを構築している方法は、次のようになります。私はやりたいこと

- (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 = CGRectMake(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)); 
} 

は次のとおりです。

ユーザーがフォームに入力した場合。私はそれをローカルのXMLファイルとして保存し、そこに値を入れる必要があります。 これを達成する最も良い方法は何ですか?

答えて

0

これらの値をplistに保存するだけで済みます。

このリンクは、plistを作成する方法を示します。

Property List Programming Guide

あなたはただ、この方法[label text]を使用してラベル内の各値を読み取ることができます。

セグメント化されたコントロールでは、次のメソッドを使用します。 [answer titleForSegmentAtIndex:index];

これらのメソッドは、NSDictionaryに格納できるNSStringを返します。

これらの値を取得したら、NSDictionaryオブジェクトを作成して[dictionary writeToFile:pathToDirectory atomically:YES]を呼び出します。

+0

私は今作成したテキストフィールドとセグメント化されたコントロールをどのようにターゲットにしてそれらの値を取得するかを知りたいです。 –

関連する問題