2016-04-15 45 views
0
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 


    NSURL *url=[NSURL URLWithString:@"http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"]; 
    NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url]; 
    [[NSURLConnection alloc]initWithRequest:request delegate:self]; 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 

    _data=[[NSMutableData alloc]init]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)thedata{ 

    [_data appendData:thedata]; 



-(void)connectionDidFinshLoading:(NSURLConnection *)connection{ 

    _name=[NSJSONSerialization JSONObjectWithData:_data options:NSJSONReadingMutableContainers error:nil]; 
     [self.tableView reloadData]; 
+1

需要更多信息。什麼是不加載? UI顯示?空桌子?任何錯誤消息? –

+0

Plesae使用基本格式選項 – Daenarys

回答

0

{ 「GEONAMES」:[{ 「LNG」: - 99.12766456604, 「geonameId」:3530597, 「COUNTRYCODE」: 「MX」, 「名稱」:「Mexiko -Stadt「, 」fclName「:」city,village,...「, 」toponymName「:」Mexico City「, 」fcodeName「:」政治實體的資本「, 」wikipedia「:」en。 wikipedia.org/wiki/Mexico_City」, 「LAT」:19.428472427036, 「FCL」: 「P」, 「種羣」:12294193, 「FCODE」: 「PPLC」 },{ 「LNG」:116.397228240967 , 「geonameId」:1816670, 「COUNTRYCODE」: 「CN」, 「名」: 「北平」, 「fclName」: 「城市,村莊,...」, 「toponymName」: 「北京」, 「fcodeName」:「政治實體的首都」, 「維基百科」:「en.wikipedia.org/wiki/Beijing」, 「lat」:39.9074977414405, 「fcl」:「P」,「population」:11716620 , 「FCODE」: 「PPLC」 }]}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [self.name count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

UITableViewCell *cell = 
       [tableView dequeueReusableCellWithIdentifier:@"Cell" 
          forIndexPath:indexPath]; 

    // Configure the cell... 
    cell.textLabel.text=[[self.nameobjectAtIndex:indexPath.row]objectForKey:@"geonameId"]; 

    return cell; 
} 

其沒有顯示任何錯誤消息.....其運行......和表示空表視圖.....