Skip to content

Instantly share code, notes, and snippets.

@yuxiangq
Last active August 29, 2015 14:19
Show Gist options
  • Save yuxiangq/6c282d9899fe28fe59e4 to your computer and use it in GitHub Desktop.
Save yuxiangq/6c282d9899fe28fe59e4 to your computer and use it in GitHub Desktop.
prototypeCustomCell的初始化
//仅展示部分代码
@interface ViewController ()
/**
* 原型cell
*/
@property (strong,nonatomic) CustomCell *prototypeCustomCell;
/**
* 数据源
*/
@property (strong,nonatomic) NSArray *dataArray;
@end
- (void)viewDidLoad{
[super viewDidLoad];
//...
[self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:kCustomCellIdentifier];
self.prototypeCustomCell=[self.tableView dequeueReusableCellWithIdentifier:kCustomCellIdentifier];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
[self.prototypeCustomCell configurationCell:self.dataArray[indexPath.row]];
[self.prototypeCustomCell setNeedsLayout];
[self.prototypeCustomCell layoutIfNeeded];
CGFloat height=[self.prototypeCustomCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height+1;
return height;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment