欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS中UITableView使用的常見問題總結(jié)

 更新時間:2017年03月25日 10:49:48   作者:四號程序員  
這篇文章主要總結(jié)了iOS中UITableView使用的常見問題,其中包括如何設置headerView以及其高度、去掉多余cell的分割線 以及如何設置section數(shù)、行數(shù)等一系列的問題,文中介紹的更詳細,需要的朋友們下面來一起看看詳細介紹吧。

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

tableView.tableHeaderView = myHeaderView
 
let height = headerView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height
var frame = headerView.frame
frame.size.height = height
headerView.frame = frame

2、去掉多余cell的分割線

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

3、如何設置section數(shù)、行數(shù)

extension MyViewController: UITableViewDataSource {
 
 // section數(shù)
 func numberOfSections(in: UITableView) -> Int {
 }
 
 // row數(shù)
 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 = 80
tableView.rowHeight = UITableViewAutomaticDimension

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

tv.estimatedSectionHeaderHeight = 20
tv.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是將顏色轉(zhuǎn)化為純色View的類,網(wǎng)上可以搜到

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 8系統(tǒng)上,點擊cell push一個vc,再pop回來,部分cell高度會亂掉

需要強制實現(xiàn)下估算高度

傳送門

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

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對各位iOS開發(fā)者們能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關文章

  • iOS利用Block逆向傳值的方式詳解

    iOS利用Block逆向傳值的方式詳解

    大家應該都有所了解在iOS開發(fā)中,常見的幾種逆向傳值方式,有代理(delegate)、通知(NSNotification),block等等,之前已經(jīng)給大家介紹了通過代理實現(xiàn)逆向傳值的方法,這篇文章來給大家介紹如何通過Block進行逆向傳值,有需要的朋友們下面跟著小編一起來學習學習吧。
    2016-12-12
  • iOS自定義UIScrollView的滾動條實例代碼

    iOS自定義UIScrollView的滾動條實例代碼

    本篇文章主要介紹了iOS自定義UIScrollView的滾動條實例代碼,詳細的介紹了自定義滾動條的示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • 2016年iOS公開可利用漏洞總結(jié)

    2016年iOS公開可利用漏洞總結(jié)

    本文總結(jié)了2016年比較嚴重的iOS漏洞(可用于遠程代碼執(zhí)行或越獄),希望能夠?qū)Υ蠹乙苿影踩矫娴墓ぷ骱脱芯繋硪恍椭?/div> 2016-12-12
  • iOS表視圖之下拉刷新控件功能的實現(xiàn)方法

    iOS表視圖之下拉刷新控件功能的實現(xiàn)方法

    下拉刷新是重新刷新表視圖或列表,以便重新加載數(shù)據(jù),這種模式廣泛用于移動平臺,相信大家對于此也是非常熟悉的,那么iOS是如何做到的下拉刷新呢?下面小編給大家分享iOS表視圖之下拉刷新控件的實現(xiàn)方法,一起看看吧
    2017-01-01
  • IOS客戶端接入微信支付

    IOS客戶端接入微信支付

    對于一個ios的app,如果有一些虛擬的商品或者服務需要通過在線支付來收費的話,一般有幾種主流的選擇。如果是通過APP調(diào)用支付平臺APP的思路的話,一個是調(diào)起支付寶客戶端,一個則是調(diào)起微信支付。本文給大家分享ios客戶端接入微信支付,需要的朋友可以參考下
    2015-09-09
  • iOS實現(xiàn)日歷翻頁動畫

    iOS實現(xiàn)日歷翻頁動畫

    本文的內(nèi)容主要是在IOS中實現(xiàn)日歷翻頁的動畫,界面簡單但效果很好,以后可以運用到app中,下面一起來看看。
    2016-08-08
  • iOS通過http post上傳圖片

    iOS通過http post上傳圖片

    這篇文章主要介紹了iOS通過http post上傳圖片的相關資料,需要的朋友可以參考下
    2016-03-03
  • Objective-C 宏定義詳細介紹

    Objective-C 宏定義詳細介紹

    這篇文章主要介紹了Objective-C 宏定義詳細介紹的相關資料,這樣開發(fā)起來,更有效率,更好,更簡潔,需要的朋友可以參考下
    2016-10-10
  • iOS使用pageViewController實現(xiàn)多視圖滑動切換

    iOS使用pageViewController實現(xiàn)多視圖滑動切換

    這篇文章主要為大家詳細介紹了iOS使用pageViewController實現(xiàn)多視圖滑動切換,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • IOS中用正則表達式判斷輸入的內(nèi)容為8-16位且同時包含數(shù)字和字母

    IOS中用正則表達式判斷輸入的內(nèi)容為8-16位且同時包含數(shù)字和字母

    這篇文章主要介紹了IOS中用正則表達式判斷輸入的內(nèi)容為8-16位且同時包含數(shù)字和字母,需要的朋友可以參考下
    2017-06-06

最新評論