嗨,我有一个表格,其中包含来自带有地址的 json 信息,按下按钮时我设法按社区对它们进行排序,我想用相同的按钮创建具有社区的可扩展和可折叠部分。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] init];
}
NSString *cellName = [[myArray objectAtIndex:indexPath.row] valueForKeyPath:@"name"];
NSString *cellState = [[myArray objectAtIndex:indexPath.row] valueForKeyPath:@"desc"];
NSString *cellTodo = [NSString stringWithFormat:@"%@: %@", cellState, cellName];
[[cell textLabel] setFont:[UIFont systemFontOfSize: 11.0]];
cell.textLabel.text = cellTodo;
return cell;
}
- (IBAction)PorBarrio:(id)sender {
NSSortDescriptor * sortDesc = [[NSSortDescriptor alloc] initWithKey:@"desc" ascending:YES];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:sortDesc]];
[myTableView reloadData];
}