2013-04-11 71 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是它是強類型的