最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

1、如何設(shè)置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、如何設(shè)置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、設(shè)置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、設(shè)定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ā)者們能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論

鹰潭市| 玉环县| 梁平县| 达日县| 东阿县| 伊金霍洛旗| 巴彦淖尔市| 新乐市| 周至县| 淳安县| 三穗县| 康乐县| 娄底市| 娱乐| 漳平市| 华容县| 商洛市| 宜兴市| 三明市| 牟定县| 长乐市| 齐齐哈尔市| 中山市| 礼泉县| 禄丰县| 赤峰市| 龙陵县| 体育| 峨眉山市| 武川县| 平塘县| 尤溪县| 云龙县| 沛县| 合水县| 广汉市| 商洛市| 阿拉善右旗| 宁乡县| 泸西县| 西贡区|