ios11使用tableView的一些问题
来源:互联网 发布:matlab中粒子群算法 编辑:程序博客网 时间:2024/05/20 17:41
随着ios11,xcode9的到了,一些新旧API的更替,以往tableView上可以正常显示的界面出现了一些问题,在这里简单记录一下
首先,如果在项目的tableView中,使用了
- (CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath;
方法的话,那么在ios11下显示就会发现设置的高度全不见了,并且你还会发现,以往的各个section之间的间距,到这里也没有了
解决方法:
苹果在ios11中,对tableView新增了许多属性,其中有几条就是关于cell高度以及头尾视图高度的
只需要判断好系统版本,在初始化tableView时加上一下代码就可以了
if (iOS11Later) { _tableView.estimatedRowHeight = 0; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; }
如果你的cell没有固定行高,就不需要加_tableView.estimatedRowHeight = 0;
否则当你出现indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1之类的判断时,将会出现问题
cell侧滑删除的问题
ios11引进了两个新的cell侧滑的代理方法
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
第一个控制cell右滑出现的按钮,第二个控制左滑删除,置顶等按钮
这里举一个左滑删除的例子
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { //删除 UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { //这里删除按钮点击或滑到最左侧时会触发这个回调 completionHandler (YES); //这里回调YES是执行删除操作 }]; //下面的属性可以自定义删除的样式 deleteRowAction.image = [UIImage imageNamed:@"address_cell_delete"]; deleteRowAction.backgroundColor = [UIColor colorWithHexString:@"f4f4f4" alpha:1]; UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]]; return config;}
这里两个枚举值
UIContextualActionStyleNormal,//默认的滑动
UIContextualActionStyleDestructive//当滑动到最左侧时,会直接触发删除操作
注:
这里ios11的方法总会提示一些警告,一些提示让你对ios11进行版本判断,本人认为这些多此一举,只有在ios11时才会进入此方法中,无需一些多余的判断;
还有一个比较有意思的问题是,在自定义滑动删除样式的时候,通过deleteRowAction.image = [UIImage imageNamed:@”address_cell_delete”];给设置图片的时候,无论怎么去渲染,更改图片的颜色,在这里都会展示成白色的图片,目前还没有找到方法去解决,有解决的朋友欢迎替小弟解惑.
- ios11使用tableView的一些问题
- tableView的一些使用
- IOS11使用IQKeyboardManager导致tableview位置变形
- iOS11一些坐标原点问题
- iOS11 设置tableview的header或者footer高度无效的问题
- iOS11 UITbleView适配的一些问题及解决方法
- 对ios11 适配问题1——tableView的下拉刷新控件下移
- iOS11 tableView内容向下偏移20pt或向下偏移64pt的问题?
- 有关使用tableview的问题
- iOS11 Tableview顶部空白和Section Header留白问题
- CollectionView 与 TableView 的一些问题
- 定位服务在iOS11系统上不能使用的问题
- iOS11适配tableview
- ios11 tableview下移
- tableView一些小问题
- iOS11问题: 定位服务在iOS11系统上不能使用?
- iOS11问题: 定位服务在iOS11系统上不能使用?
- iOS11之后刷新tableview会出现漂移的现象解决办法
- VB常用控件和变量的命名规则
- Java中的synchronized
- hdu 1880(hash字符串+二分查找)
- CodeForces-208B Solitaire
- Moving Tables
- ios11使用tableView的一些问题
- 构造表达式树
- codeforces 582D
- 【HDU4374】One hundred layer-单调队列优化DP
- tablayout
- 模拟 [bzoj 4582] Diamond Collector
- 遇到多个构造器参数时要考虑用构建器Bulider
- 后缀数组入门练习
- QGraphicsItem的缩放