UITableView的cell动态高度的方法
2013-05-28 18:12
441 查看
常规办法:
然后:
比较好的做法:
- (CGFloat)tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath { if(0 == [indexPath row]) { return 10; } if(1 == [indexPath row]) { return 30; } }
然后:
- (CGFloat)tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath { if( 0 == [indexPath row]) { // xxxx cell.contoneview = [[UIView allco] initwhithframe:CGRectMake(0, 0, 80, 10)]; } if( 1 == [indexPath row]) { //ooo cell.contoneview = [[UIView allco] initwhithframe:CGRectMake(0, 0, 80, 30)]; } }
比较好的做法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; UILabel *label = (UILabel *)[cell viewWithTag:1]; CGRect cellFrame = [cell frame]; cellFrame.origin = CGPointMake(0, 0); CGRect rect = CGRectInset(cellFrame, 100, 40); label.frame = rect; if (label.frame.size.height > 30) { cellFrame.size.height = 150 + label.frame.size.height -30; } else { cellFrame.size.height = 150; } [cell setFrame:cellFrame]; } return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; return cell.frame.size.height; }
相关文章推荐
- UITableView性能优化 以及动态计算cell高度 新方法
- 几种设置UITableView的cell动态高度的方法
- 几种设置UITableView的cell动态高度的方法
- 总结了几种设置UITableView的cell动态高度的方法
- IOS 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- (原创)iOS中cell高度自适应方法UITableView设置
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- UITableView cell 半透明效果,改变cell高度时背景不闪的解决方法
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- [译]使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- iOS UITableView+FDTemplateLayoutCell 配合AutoLayout分分钟教你实现动态高度自适应
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 动态改变UITableView中的Cell高度
- (转)iPhone实战:动态改变UITableView中的Cell高度
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 提升含有动态高度UITableViewCell的UITableView的运行效率