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文件,並將其中的值保存。 達成此目的的最佳方法是什麼?
我想知道如何針對那些我剛剛創建的文本框和分段控件,並從中獲取值。 –