美文网首页
UITableViewAutomaticDimension

UITableViewAutomaticDimension

作者: 路漫漫其修远兮Wzt | 来源:发表于2019-07-31 15:38 被阅读0次
使用UITableViewAutomaticDimension更新UITableViewCell

iOS 8 UITableViewAutomaticDimension

 - (void)viewDidLoad {
   [super viewDidLoad]; 
 
   self.heightAtIndexPath = [NSMutableDictionary new]; 
   self.tableView.rowHeight = UITableViewAutomaticDimension; 
} 
 
  - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
   NSNumber * height = [self.heightAtIndexPath objectForKey:indexPath]; 
     if(height){
        return height.floatValue; 
} else {
     return UITableViewAutomaticDimension; 
} 
} 
 
  - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
     NSNumber * height = @(cell.frame.size.height); 
     [self.heightAtIndexPath setObject:height forKey:indexPath]; 
} 
  

相关文章

网友评论

      本文标题:UITableViewAutomaticDimension

      本文链接:https://www.haomeiwen.com/subject/bxrtdctx.html