forkingdog / forkingdog/UITableView-FDTemplateLayoutCell
iOS 7 代码写 cell 约束时,高度计算问题
- Dominant language
- Objective-C
- Stars
- 9.9k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
因为我这儿的项目的架构中规定,cell 只关注自己的 view,不允许将与dataEntiy 传递给 cell,所以产生了以下问题。
### 情况
1. 如果是用 IB 做的 cell 没有问题。
2. 如果把约束都写在initWithStyle:reuseIdentifier 也都没有问题。
3. 如果都写在 updateContraints 里时就会有问题。iOS7里,当执行到`fd_heightForCellWithIdentifier:configuration` 中的`systemLayoutSizeFittingSize:`时,不能自动执行 cell 的 `cell updateContraints`,所以自动计算出的高度都是0。在 iOS 8与 iOS9里,会自动执行 `cell updateContraints`,所以高度没有问题。
### 解决方法1
我想可不可以在 `systemLayoutSizeFittingSize`前加上判断,以保证 iOS 7 cell 的高度。当然,加这样的判断后,如果使用的是1、2情况,陡增了计算 cell 高度的时间
```
if (iOS7){
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
}
```
### 解决方法2
告诉大家 cell 的约束应该怎么写,要么使用 IB,要么都写在 initWithStyle:reuseIdentifier
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.