2016-11-19 91 views
-2

如何從此URL獲取所有編號,並在uitableview「http://www.thomas-bayer.com/sqlrest/CUSTOMER/」中顯示。XML解析獲取編號

- (void)viewDidLoad 
{ 

    NSURL *URL = [[NSURL alloc] initWithString:@"http://www.thomas-bayer.com/sqlrest/CUSTOMER/"]; 

     NSString *xmlString = [[NSString alloc] initWithContentsOfURL:URL encoding:NSUTF8StringEncoding error:NULL]; 

     xmlDoc = [NSDictionary dictionaryWithXMLString:xmlString]; 


     NSLog(@"dictionary: %@", xmlDoc); 



    } 


    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return 1; 
    } 

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


    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *cellID = @"Cell"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; 

     if (cell == nil) { 

      cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; 
     } 


     cell.textLabel.text = [[[xmlDoc objectForKey:@"CUSTOMER"]objectAtIndex:indexPath.row]objectForKey:@"__text"]; 


     return cell; 

    } 

我只得到0,1,2值顯示在uitableview中,並忽略剩餘的ID?

+0

你能告訴我們,你已經試過了嗎? – FelixSFD

+0

我試圖遵循一個非常類似於http://www.theappguruz.com/blog/xmlparsing-with-nsxmlparser-tutorial的xml教程,但最終沒有顯示任何內容。 – RKrish

回答

0

使用此庫將XMLData轉換爲NSDictionary對象。 https://github.com/nicklockwood/XMLDictionary然後只需從NSDictionary對象中獲取所需的數據並將其更新到TableView

+0

我只有0,1,2的值顯示在uitableview中,並忽略剩餘的ID? – RKrish

+0

請分享您的代碼,以便我可以找到缺陷並​​告訴您。 –

+0

我也編輯你的問題現在檢查它。 –