开发者

Turning additional strings in this JSON array into a UITableView Detail

开发者 https://www.devze.com 2023-01-02 03:25 出处:网络
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 t

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 ce开发者_开发技巧llForRowAtIndexPath:(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];

}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消