0

我正在将 xml 数据解析为表格视图,这里我正在检索问题答案标签,问题标签中出现问题仅显示一个问题剩余问题未显示,这是 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