Xcode 7中Static Cells自动计算高度失效的解决方法
生活随笔
收集整理的這篇文章主要介紹了
Xcode 7中Static Cells自动计算高度失效的解决方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
在iOS 8及以后的版本,我們可以這樣設置tableView,讓它自動計算高度
self.tableView.estimatedRowHeight = 44 self.tableView.rowHeight = UITableViewAutomaticDimension但升級到Xcode 7之后發現這個方法對設置為Static Cells的table view就不管用了(這里探討了原因)。我們可以通過實現UITableViewDelegate里的方法達到同樣的效果,代碼如下:
Objective-C:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {return UITableViewAutomaticDimension; }- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {return 44; }Swift:
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {return 44 }override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {return UITableViewAutomaticDimension }轉載于:https://my.oschina.net/aetern/blog/515015
總結
以上是生活随笔為你收集整理的Xcode 7中Static Cells自动计算高度失效的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何打印一个Struct来调试
- 下一篇: android SDK manager