Creating Drill-Down Detail UITableView from JSON NSDictionary

Posted by Michael Robinson on Stack Overflow See other posts from Stack Overflow or by Michael Robinson
Published on 2010-06-10T19:10:57Z Indexed on 2010/06/10 19:12 UTC
Read the original article Hit count: 703

I'm have a load of trouble finding out how to do this,

I want to show this in a UITableDetailView (Drill-Down style) with each item in a different cell. All of the things I've read all show how to load a single image on the detail instead of showing as a UITableView. Does the dictionary have to have "children" in order to load correctly? Here is the code for the first view creating *dict from the JSON rowsArray.

I guess what I'm looking for is what to put in the FollowingDetailViewController.m to see the rest of *dict contents, so when selecting a row, it loads the rest of the *dict.

I have rowsArray coming back as follows:

'{ loginName = Johnson;

memberid = 39;

name = Kris;

age = ;}, etc,etc...

Thanks,

// SET UP TABLE & 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] autorelease];
}
    NSDictionary *dict = [rowsArray objectAtIndex: indexPath.row];

    cell.textLabel.text = [dict objectForKey:@"name"];
    cell.detailTextLabel.text = [dict objectForKey:@"loginName"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;   
    return cell;
}

- (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];



- (void)viewDidLoad {
    [super viewDidLoad];

//GET JSON FROM WEBSERVICES:
    NSURL *url = [NSURL URLWithString:@"http://10.0.1.8/~imac/iphone/jsontest.php"];
    NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];

    NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;

    NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
    if (dict)
    {
        rowsArray = [dict objectForKey:@"member"];
        [rowsArray retain];
    }


[jsonreturn release];

}

//GO  TO DETAIL VIEW:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    FollowingDetailViewController *aFollowDetail = [[FollowingDetailViewController alloc] initWithNibName:@"FollowingDetailView" bundle:nil];
    [self.navigationController pushViewController:aFollowDetail animated:YES];
}

© Stack Overflow or respective owner

Related posts about JSON

Related posts about uitableview