I have an UITableView which includes a list of UITableViewCells. And I set the heights of UITableViewCells in method (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
.
However, I need to increase the height of UITableViewCell
when it is selected. For example开发者_开发知识库, the height of UITableViewCell
needs to increase 100 pixels when the cell is selected, does anyone know how to do it?
- Store selected index in your controller.
Return cell's height depending on that index:
CGFloat height = 30.0f; ... -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return indexPath.row == selectedIndex ? height+100 : height; }
Refresh tableview geometry in
didSelectRowAtIndexPath
method (empty block betweenbeginUpdates
andendUpdates
does the trick):- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ index = indexPath.row; [tableView beginUpdates]; [tableView endUpdates]; }
Make your delegate method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
return the (new) correct height and make the table view reload the given path.
精彩评论