views:

45

answers:

1

I have a NSURL request that brings back an array of "name" and "phone", "etc"... The "name" Key shows up fine on the master table, but I'm having trouble figuring out how to get the rest of the array to show up on the detail table when I select the row. (I have the DetailerTableViewController working to accept the view). Any help would be appreciated.

Thanks,

   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [rowsArray count];
NSLog(@"row count: %@",[rowsArray count]);
}

- (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)viewDidLoad {
[super viewDidLoad];

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0/255.0 green:207.0/255.0 blue:255.0/255.0 alpha:1.0];
self.title = NSLocalizedString(@"Master", @"Master");
NSURL *url = [NSURL URLWithString:@"http://10.0.1.8/~imac/iphone/jsontest.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];

NSLog(jsonreturn); // Look at the console and you can see what the results are

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

// In "real" code you should surround this with try and catch
NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
if (dict)
{
    rowsArray = [dict objectForKey:@"member"];
    [rowsArray retain];
}


NSLog(@"Array: %@",rowsArray);
NSLog(@"count is: %i", [self.rowsArray count]);


[jsonreturn release];

}
+1  A: 

You need to implement:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

to handle row selection and to push the view controller for the detail view.

lucius
Thanks - I have that and it does the push, however the resulting page is just the "name" cell.textLabel.text = [dict objectForKey:@"name"]; I want to show the name along with everything else in the array.
Michael Robinson
What do you push in this method? If you push another table view controller, you'll need to set up each row as a separate line of data. Or you could create your own view with UILabels that you fill in, in your custom UIViewController subclass.
lucius
I did push another view controller, I'm having trouble with that exact problem, I have to have a separate view controller because the view has a couple items besides the detail table, I guess my question needs to be: How do I set up separate cells for each of the items in the array from the above table?
Michael Robinson