json ios5 ничего на экране - PullRequest
0 голосов
/ 09 января 2012

Я только что установил xcode 4.2.1 с ios5, и я пытаюсь использовать json.

это мой код

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



}

в моем NSLog(@"array %@",jsonArray); я вижу все записи, все в порядке. Но в моем виде таблицы ничего нет на экране.

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

этот код работает на xcode 3, но не на xcode 4.

некоторые помогают, пожалуйста.

1 Ответ

0 голосов
/ 21 марта 2012

После того, как вы закончите загрузку данных, вы должны указать табличному представлению о перезагрузке.Я не вижу этого в вашем коде.Попробуйте что-то вроде этого:

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

Также убедитесь, что ваш TableView подключен в конструкторе через IBOutlet.В противном случае ваша команда reloadData будет игнорироваться.

...