-1

解析后我UITableView没有显示所有值XML。它只返回一行。解析xml后,为什么只显示一行而不是全部ArrayList?我检查了我的 xml php 页面。它显示所有值都很好。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[xmlcont xmlbanktransfer] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSUInteger const kMagnitudeImageTag = 0;
    static NSUInteger const kLocationLabelTag = 4;
    static NSUInteger const klocationtag = 6;
    static NSUInteger const kacctag = 8;
    static NSUInteger const knameLabelTag = 9;


    UIImageView *magnitudeImage = nil;
    UILabel*locationLabel = nil;
    UILabel*locationtag=nil;
    UILabel*acc=nil;
    UILabel*nameLabel= nil;
    //NSMutableArray *cont = [xmlcont tweets];
    // Tweet *current       = [cont objectAtIndex:indexPath.row];
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        /*//common settings
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
         cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
         cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
         cell.imageView.frame = CGRectMake(0.0f, 0.0f, 44.0f, 44.0f);
         cell.imageView.clipsToBounds = YES;

         */
    }

    for(UIView *view in cell.contentView.subviews)
    {
        if ([view isKindOfClass:[UIView class]])
        {
            [view removeFromSuperview];
        }
    }
    NSMutableArray *cont = [xmlcont xmlbanktransfer];
    trans *current= [cont objectAtIndex:indexPath.row];
    NSLog(@"sd %@",current.date);
     NSLog(@"sd %@",current.name);
    locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(5,10, 250, 20)];
    locationLabel.tag = kLocationLabelTag;
    locationLabel.font = [UIFont boldSystemFontOfSize:15];
    [cell.contentView addSubview:locationLabel];

    locationLabel.text=current.name;
    locationLabel.textColor=[UIColor colorWithRed:0.050 green:0.278 blue:0.392 alpha:1];
    //locationLabel.backgroundColor=[UIColor lightGrayColor];
    locationLabel.backgroundColor=[UIColor colorWithRed:225 green:225 blue:225 alpha:0] ;
    nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(180,10, 250, 20)];
    nameLabel.tag = knameLabelTag;
    nameLabel.font = [UIFont systemFontOfSize:13];
    [cell.contentView addSubview:nameLabel];
    nameLabel.text=current.date ;
    nameLabel.textColor=[UIColor colorWithRed:0.050 green:0.278 blue:0.392 alpha:1];
    //locationLabel.backgroundColor=[UIColor lightGrayColor];
    nameLabel.backgroundColor=[UIColor colorWithRed:225 green:225 blue:225 alpha:0] ;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

解析xml的代码:

    xmlbanktransfer=[[NSMutableArray alloc] init];
    NSURL *url=[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];


    parser=[[NSXMLParser alloc] initWithContentsOfURL:url];
    [parser setDelegate:self];
    [parser parse];
    NSLog(@"testing12 %@ ",url);
   // NSLog(@"tweets %@ ", xmlbanktransfer);
    NSLog(@"Total values = %d",[xmlbanktransfer count]);
    return self;
}

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

    if([elementName isEqualToString:@"item"])
    {
        currentTweet       = [trans alloc];
        banktransNodeContent =[[NSMutableString alloc] init];
    }
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{

    if([elementName isEqualToString:@"date"])
    {

        currentTweet.date = [currentTweet.date stringByReplacingOccurrencesOfString:@"&" withString:@" "];
        currentTweet.date = banktransNodeContent;



    }

    if([elementName isEqualToString:@"name"])
    {
        currentTweet.name =banktransNodeContent;


    }
    if ([elementName isEqualToString:@"type"])
    {
        currentTweet.type=banktransNodeContent;
    }

    if ([elementName isEqualToString:@"gross"])
    {
        currentTweet.gross=banktransNodeContent;
    }


    if ([elementName isEqualToString:@"fee"])
    {
        currentTweet.fee=banktransNodeContent;
    }

    if ([elementName isEqualToString:@"net"])
    {
        currentTweet.net=banktransNodeContent;
        NSLog(@"current tweet  %@",currentTweet.net);
    }

    if ([elementName isEqualToString:@"category"])
    {
        currentTweet.category=banktransNodeContent;
        NSLog(@"current tweet  %@",currentTweet.category);
    }

    if ([elementName isEqualToString:@"account"])
    {
        currentTweet.account=banktransNodeContent;
        NSLog(@"current tweet  %@",currentTweet.account);
    }

    if([elementName isEqualToString:@"item"])
    {

        [xmlbanktransfer addObject:currentTweet];

        currentTweet = nil;

        banktransNodeContent = nil;
    }

}




- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string


{

    NSLog(@"currentNodeContent are %@",banktransNodeContent);
    banktransNodeContent = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSLog(@"currentNodeContentstring test are %@",banktransNodeContent);

}

- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
    banktransNodeContent = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
}
4

1 回答 1

0
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[xmlcont xmlbanktransfer] count];
}

此方法告诉表格视图要填充多少个单元格

记录该值并查看它返回了多少[它现在必须返回 1,因为该表显示一行]。更正返回值,您将显示所有值

检查事项

  • 上面提到的返回值
  • 确保数组xmlbanktransfer是强类型的属性
于 2013-04-11T10:54:55.217 回答