全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

iOS中UITableView使用的常见问题总结

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数、行数

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 = 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是将颜色转化为纯色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 8系统上,点击cell push一个vc,再pop回来,部分cell高度会乱掉

需要强制实现下估算高度

传送门

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

总结

以上就是这篇文章的全部内容了,希望本文的内容对各位iOS开发者们能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。


# ios  # uitableview优化  # uitableview  # 两列  # uitableview删除行  # ios UITableView实现无数据加载占位图片  # iOS中UIScrollView嵌套UITableView的实践教程  # IOS UITableView和NavigationBar的常用设置详解  # iOS基于UITableView实现多层展开与收起  # iOS中UITableView Cell实现自定义单选功能  # iOS中的UITableView的重用机制与加载优化详解  # IOS UITableViewCell详解及按钮点击事件处理实例  # IOS中UITableView滚动到指定位置  # IOS UITableView颜色设置的实例详解  # 如何设置  # 分割线  # 他们的  # 按下  # 这篇文章  # 自带  # 谢谢大家  # 转化为  # 可以自动  # 行数  # 传送门  # 网上  # 有疑问  # indexPath  # cellForRowAt  # public 


相关文章: 如何在Golang中处理模块冲突_解决依赖版本不兼容问题  宝塔面板如何快速创建新站点?  专业制作网站的公司哪家好,建立一个公司网站的费用.有哪些部分,分别要多少钱?  制作公司内部网站有哪些,内网如何建网站?  建站之星安装路径如何正确选择及配置?  广州美橙建站如何快速搭建多端合一网站?  微信小程序 input输入框控件详解及实例(多种示例)  惠州网站建设制作推广,惠州市华视达文化传媒有限公司怎么样?  济南网站制作的价格,历城一职专官方网站?  如何解决VPS建站LNMP环境配置常见问题?  TestNG的testng.xml配置文件怎么写  如何在云主机上快速搭建网站?  建站之星如何实现PC+手机+微信网站五合一建站?  已有域名和空间如何搭建网站?  如何挑选优质建站一级代理提升网站排名?  如何在云服务器上快速搭建个人网站?  建站之星3.0如何解决常见操作问题?  如何在Windows服务器上快速搭建网站?  免费视频制作网站,更新又快又好的免费电影网站?  网站制作需要会哪些技术,建立一个网站要花费多少?  官网自助建站系统:SEO优化+多语言支持,快速搭建专业网站  制作充值网站的软件,做人力招聘为什么要自己交端口钱?  网站制作和推广的区别,想自己建立一个网站做推广,有什么快捷方法马上做好一个网站?  厦门模型网站设计制作公司,厦门航空飞机模型掉色怎么办?  小米网站链接制作教程,请问miui新增网页链接调用服务有什么用啊?  小捣蛋自助建站系统:数据分析与安全设置双核驱动网站优化  公众号网站制作网页,微信公众号怎么制作?  建站之星免费版是否永久可用?  如何用好域名打造高点击率的自主建站?  如何在企业微信快速生成手机电脑官网?  建站之星如何防范黑客攻击与数据泄露?  如何在云指建站中生成FTP站点?  免费制作海报的网站,哪位做平面的朋友告诉我用什么软件做海报比较好?ps还是cd还是ai这几个软件我都会些我是做网页的?  如何用花生壳三步快速搭建专属网站?  网站视频制作书签怎么做,ie浏览器怎么将网站固定在书签工具栏?  正规网站制作公司有哪些,目前国内哪家网页网站制作设计公司比较专业靠谱?口碑好?  如何做网站制作流程,*游戏网站怎么搭建?  深圳网站制作平台,深圳市做网站好的公司有哪些?  攀枝花网站建设,攀枝花营业执照网上怎么年审?  c++怎么编写动态链接库dll_c++ __declspec(dllexport)导出与调用【方法】  ,网页ppt怎么弄成自己的ppt?  家具网站制作软件,家具厂怎么跑业务?  导航网站建站方案与优化指南:一站式高效搭建技巧解析  如何快速辨别茅台真假?关键步骤解析  建站之星展会模版如何一键下载生成?  网站制作壁纸教程视频,电脑壁纸网站?  如何配置IIS站点权限与局域网访问?  logo在线制作免费网站在线制作好吗,DW网页制作时,如何在网页标题前加上logo?  小自动建站系统:AI智能生成+拖拽模板,多端适配一键搭建  太平洋网站制作公司,网络用语太平洋是什么意思? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。