Я слежу за обучением на iPhone, как отображать данные из удаленной базы данных на iPhone.Учебник в порядке, однако я не понимаю одну часть (а также у меня есть некоторые другие вопросы), и я надеялся, что кто-то рассудит пролить немного света.
В соответствии с кодом ниже, что сохраняет "rows = [[dict objectForKey: @" users "]];"делать?(он ищет ключ - «пользователи» и сохраняет все результаты в строках? - но что такое строка? это относится к строке таблицы?).И если да, то как можно сортировать эти данные в зависимости от информации базы данных, а не от полей?
Мой второй вопрос: как я могу манипулировать данными, чтобы в таблице отображались только поля с определенными строковыми значениями?
Спасибо за любую помощь в этом!
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://localhost:8888/jsontest.php"]; // Modify this to match your url.
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url]; // Pulls the URL
NSLog(jsonreturn); // Look at the console and you can see what the restults 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)
{
rows = [[dict objectForKey:@"users"] retain];
}
NSLog(@"Array: %@",rows);
[jsonreturn release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [rows count];
}
// Customize the appearance of table view 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];
}
// Configure the cell.
NSDictionary *dict = [rows objectAtIndex: indexPath.row];
cell.textLabel.text = [dict objectForKey:@"userid"];
cell.detailTextLabel.text = [dict objectForKey:@"email"];
return cell;
}