闲话少说,上代码:
改变cell高度的代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// If our cell is selected, return double height
if([self cellIsSelected:indexPath]) {
return kCellHeight * 2.0;
}
// Cell isn't selected so return single height
return kCellHeight;
}
在点击cell时改变cell的高度,因此在didselect中添加关键语句:
[tableView beginUpdates];
[tableView endUpdates];
didselect中的代码:
- (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 *selectState = [NSNumber numberWithBool:isSelected];
[selectedIndexes setObject:selectState forKey:indexPath];
// This is where magic happens...
[tableView beginUpdates];
[tableView endUpdates];
}
大功告成!
posted on 2013-09-30 10:02
Long 阅读(913)
评论(0) 编辑 收藏 引用 所属分类:
iOS