2013-04-11 75 views
-1

在解析XML后,我的UITableView未显示所有值。它只返回一行。解析xml后,为什么只显示一行而不是整个ArrayList?我检查了我的xml php页面。它显示所有值都很好。用于解析XMLiphone- UITableView仅显示一个值

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

代码:

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]; 
} 
+0

属性 - (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分 { 的NSLog @(“总值=%d“,[[xmlcont xmlbanktransfer] count]); return [[xmlcont xmlbanktransfer] count]; } - 检查Array有多少个元素? – Buntylm 2013-04-11 09:57:55

+0

它返回总值:1。 – Sandeep 2013-04-11 10:08:15

+0

这里是解决方案年轻人你在Array中有1个值,这就是为什么你有1个UITableViewCell。 – Buntylm 2013-04-11 10:09:35

回答

0
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

此委托功能给数据源返回在表视图的给定部分中的行的数目。 如果你在数组中有1个对象(如你问它的1),应该只创建1个UITableViewCell。 如果您接受更多,则应该与您的parsing XML有一些问题.Xml和解析技术不同于开发人员开发人员。所以尽量在那里宇都走错了一步step.i可以给简单的链接,学习Xml parsing in iPhone

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

这个方法告诉tableview中有多少细胞填充

登录值,看看它有多少回[它必须是1,现在回来了,因为表显示一行] .Correct的返回值,你都值显示

检查事项

  • 惩戒上述
  • 提到urning值确保阵列xmlbanktransfer是它是强类型的