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

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

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

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+自動(dòng)計(jì)算行高、section高度

tableView.estimatedRowHeight = 80
tableView.rowHeight = UITableViewAutomaticDimension

實(shí)際上,sectionHeader高度也可以自動(dòng)算高

tv.estimatedSectionHeaderHeight = 20
tv.sectionHeaderHeight = UITableViewAutomaticDimension

當(dāng)然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、點(diǎn)擊cell有陰影,抬起時(shí)候陰影消失

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

8、iPad的UITableViewCell自動(dòng)縮進(jìn)的問(wèn)題

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

Swift版:

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

9、設(shè)定UITableviewCell按下的點(diǎn)擊效果

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

PureColorView是將顏色轉(zhuǎn)化為純色View的類(lèi),網(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)上,點(diǎn)擊cell push一個(gè)vc,再pop回來(lái),部分cell高度會(huì)亂掉

需要強(qiáng)制實(shí)現(xiàn)下估算高度

傳送門(mén)

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

總結(jié)

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

相關(guān)文章

最新評(píng)論

宝丰县| 安庆市| 乐清市| 昌宁县| 揭西县| 台湾省| 乳源| 霞浦县| 芜湖市| 大方县| 运城市| 梓潼县| 阿克陶县| 长泰县| 富宁县| 固安县| 池州市| 恩平市| 得荣县| 罗城| 长岛县| 工布江达县| 三门县| 揭西县| 夏邑县| 天长市| 宝应县| 五台县| 台南市| 云阳县| 黄平县| 武平县| 高清| 新疆| 手机| 改则县| 清镇市| 中方县| 松滋市| 漳平市| 夏河县|