- Group樣式下第一個(gè)section的高度必須為1的問題解決:
override func viewDidLoad() {
tableView.contentInset = UIEdgeInsets(top: -1, left: 0, bottom: 0, right: 0)
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 0 {
return 0.1
} else {
return 0
}
}
- 去掉空白行的橫線
override func viewDidLoad() {
tableView.tableFooterView = UIView()
}
- TableView自動(dòng)高度
override func viewDidLoad() {
tableView.estimatedRowHeight = 80
tableView.rowHeight = UITableViewAutomaticDimension
}
- TableView自動(dòng)高度不適用的情況,比如圖片異步加載完畢后刷新Cell高度
var imgCellHeightList = [Int : CGFloat]() // 緩存高度的數(shù)組
cell?.imageview.setImage(url: url, holder: "logo", onCompletion: { [weak self] (image, err, _, _) in
guard let sf = self else { return }
if sf.imgCellHeightList[indexPath.row] != nil { return }
if let img = image {
let h = (img.size.height/img.size.width)*UIScreen.main.bounds.width
sf.tableView.beginUpdates() // 關(guān)鍵代碼
sf.imgCellHeightList[indexPath.row] = h // 存儲(chǔ)高度
sf.tableView.endUpdates() // 關(guān)鍵代碼
} else {
log(err?.localizedDescription)
}
})
*取消 TableView plain模式下section header 懸停效果
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
let sectionHeaderHeight: CGFloat = 49.0 // section高度
if (offsetY <= sectionHeaderHeight && offsetY >= 0) {
scrollView.contentInset = UIEdgeInsetsMake(-offsetY, 0, 0, 0)
} else if (offsetY >= sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0)
}
}