首页 > 移动平台 > 详细

IOS 根据cell内容设置cell的高度

时间:2015-06-08 19:06:50      阅读:250      评论:0      收藏:0      [点我收藏+]

这里要涉及到tableview 的两个方法

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 和

 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

我们要清楚这两个方法的调用顺序,先heightForRowAtIndexPath然后是cellForRowAtIndexPath

 

//动态获取cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; return cell.frame.size.height; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"HomeCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell = [[UITableViewCell alloc] initWithFrame:CGRectZero];
    //设置cell数据
    return cell;
}

 

IOS 根据cell内容设置cell的高度

原文:http://www.cnblogs.com/tate-zwt/p/4561265.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!