2012-01-08 10 views
0

ios5でxcode 4.2.1をインストールしました.jsonを使用しようとしています。私はすべてのレコードを参照することができ、私のNSLog(@"array %@",jsonArray);json ios5画面に何も表示されない

この私のコード

-(void)start 

{ 
    responseData = [[NSMutableData data]retain]; 
    membreArray = [NSMutableArray array]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http:******.php"]]; 
    [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

} 
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [responseData setLength:0]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [responseData appendData:data]; 
} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    NSLog(@"error %@",error); 
} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    [connection release]; 

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

    [responseData release]; 

    jsonArray = [responseString JSONValue]; 

    NSLog(@"array %@",jsonArray); 



} 

、すべてがOKです。しかし、私のテーブルビューでは画面に何も表示されません。 Xcodeの3ではなく、Xcodeで4

サムスの

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

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    // Configure the cell. 

    NSDictionary *dico = [self.jsonArray objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [dico objectForKey:@"name"]; 


    return cell; 
} 

このコードの動作をしてください役立ちます。

答えて

0

データのロードが完了したら、テーブルビューにリロードを指示する必要があります。私はあなたのコードでそれを見ていないよ。このような何かを試してみてください:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    [connection release]; 

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

    [responseData release]; 

    jsonArray = [responseString JSONValue]; 

    NSLog(@"array %@",jsonArray); 
    /* This tells your tableView to reload */ 
    [tableView reloadData]; 
} 

をまた、あなたのテーブルビューはIBOutlet経由デザイナーに接続されていることを確認してください。さもなければあなたのreloadDataコマンドはろうの耳の上に落ちるでしょう。

関連する問題