Превращение дополнительных строк в этом массиве JSON в UITableView Detail - PullRequest
0 голосов
/ 05 июня 2010

У меня есть запрос NSURL, который возвращает массив «name» и «phone», «etc» ... Ключ «name» хорошо отображается на главной таблице, но у меня возникают проблемы с выяснением, как чтобы остальная часть массива отображалась в таблице подробностей, когда я выбираю строку. (У меня есть DetailerTableViewController, работающий, чтобы принять представление). Любая помощь будет оценена.

Спасибо

   - (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 Ответ

1 голос
/ 05 июня 2010

Вам необходимо реализовать:

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

, чтобы обработать выбор строки и нажать контроллер вида для подробного вида.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...