views:

503

answers:

1

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];
}
A: 

Don't use a blocking call to retrieve the JSON. If your network is slow your app will hang. You should use an async method to retrieve the data.

Look into loading the JSON contents into a model object. Then use an array of models to power your tableview. DidSelectRowAtIndexPath could then pass a instance of model object into your detail view either through a custom initializer or by setting a property after you alloc/init it. Your question is pretty hard to parse so I'm not sure if I'm addressing what you are after. Take a look at the numerous samples for table view UI hierarchies on the developer site.

Nick
Thanks, I am leaning toward your method on both counts, After I got the table loaded I was going to save the array to a .plist for persistence and reload from there upon launch. checking to see if data was available. I can save and use the JSON Object model instead, correct?
Michael Robinson
I just mean model object as a generic nsObject tailored to your purposes. You could persist to plist, sqllite, core data etc.
Nick