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

来源:互联网 发布:centos入侵 编辑:程序博客网 时间:2024/06/10 06:26

原来的网址:http://mn0421.blog.163.com/blog/static/20492067320131273336326/

交流开发群:132913650

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

NSMutableDictionary *selectedIndexes;

- (BOOL)cellIsSelected:(NSIndexPath*)indexPath;


- (void)viewDidLoad

{

    [super viewDidLoad];

    selectedIndexes = [[NSMutableDictionaryallocinit];

}


- (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

[tableViewdeselectRowAtIndexPath:indexPathanimated:TRUE];

// Toggle 'selected' state

BOOL isSelected = ![selfcellIsSelected:indexPath];

// Store cell 'selected' state keyed on indexPath

NSNumber *selectedIndex = [NSNumbernumberWithBool:isSelected];

[selectedIndexessetObject:selectedIndex forKey:indexPath];

       

// This is where magic happens...

[self.tableView beginUpdates];

[self.tableView endUpdates];

}



0 0
原创粉丝点击