每当我重新加载tableView时,在cellForRowAt之后都会调用heightForRowAt。它遵循的顺序是:
numberofsections -> numberOfRowsInSection -> cellForRowAt -> heightForRow我重写了numberOfSections, numberOfRowsInSection, viewForHeaderInSection方法。这些对调用heightForRow和cellForRowAt的顺序有影响吗?
我使用的是Xcode9.1,也就是运行在iOS 11上的Swift 3。
发布于 2017-11-04 01:42:40
这里有两个选项:
扩展字符串{ func height(withConstrainedWidth width: CGFloat,font: UIFont) -> CGFloat { let constraintRect = CGSize(width: width,height:.greatestFiniteMagnitude) let boundingBox = self.boundingRect(with: constraintRect,options:.usesLineFragmentOrigin,attributes: NSAttributedStringKey.font: font,context: nil) return ceil(boundingBox.height) } func width(withConstraintedHeight height: CGFloat,font: UIFont) -> CGFloat { let constraintRect = CGSize(width:.greatestFiniteMagnitude,height: height)让boundingBox = self.boundingRect(with: constraintRect,options:.usesLineFragmentOrigin,attributes: NSAttributedStringKey.font: font,context: nil) return ceil(boundingBox.width) } }
希望能对你有所帮助!
https://stackoverflow.com/questions/47094697
复制相似问题