国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS中UITableView使用的常見問題總結

2019-10-21 18:47:35
字體:
來源:轉載
供稿:網友

1、如何設置headerView以及其高度

tableView.tableHeaderView = myHeaderView let height = headerView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).heightvar frame = headerView.frameframe.size.height = heightheaderView.frame = frame

2、去掉多余cell的分割線

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

3、如何設置section數、行數

extension MyViewController: UITableViewDataSource {  // section數 func numberOfSections(in: UITableView) -> Int { }  // row數 public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { }  // 在section和row下,cell public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { } }

4、iOS 8+自動計算行高、section高度

tableView.estimatedRowHeight = 80tableView.rowHeight = UITableViewAutomaticDimension

實際上,sectionHeader高度也可以自動算高

tv.estimatedSectionHeaderHeight = 20tv.sectionHeaderHeight = UITableViewAutomaticDimension

當然sectionFooter也可以,不再贅述

5、禁用tableview自帶的分割線

tv.separatorStyle = .none

6、設置sectionHeader和sectionFooter,以及他們的高度

view

extension MyViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {  }  func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {  }}

高度

extension TTEntranceExamReportViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { }  func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { }}

7、點擊cell有陰影,抬起時候陰影消失

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: no) // other code}

8、iPad的UITableViewCell自動縮進的問題

if (IS_IPAD && [_tableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)]) { _tableView.cellLayoutMarginsFollowReadableWidth = NO;}

Swift版:

if IS_IPAD, #available(iOS 9.0, *) { tableView.cellLayoutMarginsFollowReadableWidth = false}

9、設定UITableviewCell按下的點擊效果

cell.selectedBackgroundView = [[PureColorView alloc] initWithColor:[UIColor redColor]];

PureColorView是將顏色轉化為純色View的類,網上可以搜到

10、sectionHeader不吸頂

let tv = UITableView(frame: CGRect.zero, style: .grouped)

11、使用.groupted后,TableView底部有20px多余空白

tv.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: CGFloat.leastNormalMagnitude))

12、ios/238190.html">ios 8系統上,點擊cell push一個vc,再pop回來,部分cell高度會亂掉

需要強制實現下估算高度

傳送門

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { return self.tableView(tableView, heightForRowAt: indexPath)}

總結

以上就是這篇文章的全部內容了,希望本文的內容對各位iOS開發者們能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網的支持


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 界首市| 柘城县| 波密县| 天水市| 盈江县| 满洲里市| 永济市| 印江| 临西县| 镇远县| 潼关县| 皮山县| 合作市| 舞阳县| 博湖县| 丰镇市| 农安县| 阜南县| 五原县| 淮滨县| 白银市| 南漳县| 南木林县| 新民市| 黄石市| 新营市| 嘉定区| 雷山县| 渝中区| 大竹县| 岚皋县| 沙洋县| 堆龙德庆县| 平定县| 讷河市| 手机| 宜兴市| 荆州市| 舞钢市| 鄂州市| 霍邱县|