iOS中UITableView使用的常見問題總結(jié)
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)的問題
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的類,網(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回來,部分cell高度會(huì)亂掉
需要強(qiáng)制實(shí)現(xiàn)下估算高度
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { return self.tableView(tableView, heightForRowAt: indexPath) }
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)各位iOS開發(fā)者們能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
- ios UITableView實(shí)現(xiàn)無數(shù)據(jù)加載占位圖片
- iOS中UIScrollView嵌套UITableView的實(shí)踐教程
- IOS UITableView和NavigationBar的常用設(shè)置詳解
- iOS基于UITableView實(shí)現(xiàn)多層展開與收起
- iOS中UITableView Cell實(shí)現(xiàn)自定義單選功能
- iOS中的UITableView的重用機(jī)制與加載優(yōu)化詳解
- IOS UITableViewCell詳解及按鈕點(diǎn)擊事件處理實(shí)例
- IOS中UITableView滾動(dòng)到指定位置
- IOS UITableView顏色設(shè)置的實(shí)例詳解
相關(guān)文章
iOS自定義UIScrollView的滾動(dòng)條實(shí)例代碼
本篇文章主要介紹了iOS自定義UIScrollView的滾動(dòng)條實(shí)例代碼,詳細(xì)的介紹了自定義滾動(dòng)條的示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03iOS表視圖之下拉刷新控件功能的實(shí)現(xiàn)方法
下拉刷新是重新刷新表視圖或列表,以便重新加載數(shù)據(jù),這種模式廣泛用于移動(dòng)平臺(tái),相信大家對(duì)于此也是非常熟悉的,那么iOS是如何做到的下拉刷新呢?下面小編給大家分享iOS表視圖之下拉刷新控件的實(shí)現(xiàn)方法,一起看看吧2017-01-01iOS使用pageViewController實(shí)現(xiàn)多視圖滑動(dòng)切換
這篇文章主要為大家詳細(xì)介紹了iOS使用pageViewController實(shí)現(xiàn)多視圖滑動(dòng)切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06IOS中用正則表達(dá)式判斷輸入的內(nèi)容為8-16位且同時(shí)包含數(shù)字和字母
這篇文章主要介紹了IOS中用正則表達(dá)式判斷輸入的內(nèi)容為8-16位且同時(shí)包含數(shù)字和字母,需要的朋友可以參考下2017-06-06