没有将整个xml数据导入tableview

时间:2012-11-21 17:26:37

标签: iphone xcode uitableview xml-parsing

我将xml数据解析为表格视图,这里iam检索问题回答标记,问题标记中出现问题只显示了一个问题剩下的问题没有显示,这是网络服务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;
}

}

这是tableview方法的代码

- (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;
    }
} 

谢谢你的帮助

0 个答案:

没有答案