UITableView-FDTemplateLayoutCell自动计算UITableView高度的使用
基本應(yīng)用
如果你有self-satisfied cell,那么你應(yīng)該做的是:
#import "UITableView+FDTemplateLayoutCell.h"
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? return [tableView fd_heightForCellWithIdentifier:@"reuse identifer" configuration:^(id cell) {
? ? ? ? // Configure this cell with data, same as what you've done in "-tableView:cellForRowAtIndexPath:"
? ? ? ? // Like:
? ? ? ? // cell.model = self.datas[index.row];
? ? }];
}
進階應(yīng)用(iOS7下也能用)
Since iOS8, -tableView:heightForRowAtIndexPath: will be called more times than we expect, we can feel these extra calculations when scrolling. So we provide another extension with caches:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? return [tableView fd_heightForCellWithIdentifier:@"identifer" cacheByIndexPath:indexPath configuration:^(id cell) {
? ? ? ? // configurations
? ? }];
}
總結(jié)
以上是生活随笔為你收集整理的UITableView-FDTemplateLayoutCell自动计算UITableView高度的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: $(document).ready();
- 下一篇: iOS 之 const