0

i have just install the xcode 4.2.1 with ios5 and i try to use json.

this my code

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



}

in my NSLog(@"array %@",jsonArray); i can see all records,everything is ok. But in my tableview nothing at the screen.

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

this code work on xcode 3 but not in xcode 4.

somes helps please.

XcodeMania
  • 305
  • 5
  • 20

1 Answers1

0

After you finish loading the data, you need to tell your tableview to reload. I'm not seeing that in your code. Try something like this:

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

Also, make sure your TableView is connected in the designer via an IBOutlet. Otherwise your reloadData command will fall on deaf ears.

ashurexm
  • 6,209
  • 3
  • 45
  • 69