美文网首页
TableView 点击cell,改变选中cell的高度

TableView 点击cell,改变选中cell的高度

作者: Flutter求学者 | 来源:发表于2020-11-10 13:58 被阅读0次

定义
NSMutableDictionary *selectedIndexes;

  • (BOOL)cellIsSelected:(NSIndexPath*)indexPath;
- (void)viewDidLoad
{
    [super viewDidLoad];
    selectedIndexes = [[NSMutableDictionaryalloc] init];
}

- (BOOL)cellIsSelected:(NSIndexPath*)indexPath {
// Return whether the cell at the specified index path is selected or not
NSNumber *selectedIndex = [selectedIndexes objectForKey:indexPath];
return selectedIndex == nil ? FALSE : [selectedIndex boolValue];
}


//设置行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
    //return 35;
    if ([self cellIsSelected:indexPath]) {
        return 60;
    }
    return 35;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
      // Deselect cell
      [tableView deselectRowAtIndexPath:indexPath animated:TRUE];
      // Toggle 'selected' state
      BOOL isSelected = ![self cellIsSelected:indexPath];
      // Store cell 'selected' state keyed on indexPath
      NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
       [selectedIndexes setObject:selectedIndex forKey:indexPath];
      // This is where magic happens...
      [self.tableView beginUpdates];
      [self.tableView endUpdates];
}

相关文章

网友评论

      本文标题:TableView 点击cell,改变选中cell的高度

      本文链接:https://www.haomeiwen.com/subject/fbcjbktx.html