0

xmlデータをテーブルビューに解析しています。ここでは、質問回答のタグを取得しています。質問タグで問題が発生しました。1つの質問のみが表示され、残りの質問は表示されませんでした。これはWebサービスhttp://www.cmellc.com/DesktopModules/CaseChallenge/ですquiz.xml
これは私が書いたコードです

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentTag = elementName;

if ([currentTag isEqualToString:@"question"])
{
    model = [[ModelDataView alloc]init];
}

if([currentTag isEqualToString:@"answer"])
{
    model_2=[[Model2 alloc]init];
}  
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if([elementName isEqualToString:@"question"])
{
    [dataControllerArray addObject:model];
}

if ([elementName isEqualToString:@"answer"])
{
    [dataControllerArray2 addObject:model_2];
    model_2 = nil;
}

currentTag = nil;

}  
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([currentTag isEqualToString:@"result"])
{
    model_2.result = string;
}

if ([currentTag isEqualToString:@"notes"])
{
    model_2.notes = string;
}

if ([currentTag isEqualToString:@"question"]) 
{
    model.question = string;
}

}

これはテーブルビューメソッドのコードです

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath   
{
    static NSString *cellIdentifier = @"cell";
   static NSString *cellIdentifier2 = @"cell2";
    UITableViewCell *cell;
if(tableView.tag==2)
  {
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
}
Model2 *obj=[modelController.dataControllerArray2 objectAtIndex:indexPath.row];
NSString *res=obj.result;
   cell.textLabel.text=res;
  return cell;
  }
     else   if(tableView.tag==1)
{
    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2] autorelease];
    }

    ModelDataView *obj=[modelController.dataControllerArray objectAtIndex:indexPath.row];
    NSString *res=obj.question;
UIWebView *_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 190)];
[self.view addSubview:_webView];
        CGRect frame = _webView.frame;
    frame.size.height = 190;
        _webView.frame = frame;
  [_webView loadHTMLString:res baseURL:[NSURL URLWithString:res]];
  return cell;
    }
} 

助けてくれてありがとう

4

0 に答える 0