iOS UITableView(四)-Cell拖动更改排序
来源:互联网 发布:淘宝购物车有什么用 编辑:程序博客网 时间:2024/06/07 23:42
本文主要内容:
1.更改cell顺序;
2.UITableview的一些小细节。
2017-03-17更新:代码更新到 Swift 3
1.更改cell顺序
效果图:
实现方式:
1.创建一个数组,存放UITableView的数据
Swift:
var dataArray: NSMutableArray = ["a", "b", "c", "e"]
Objective-C:
@property (nonatomic, strong) NSMutableArray *dataArray;
2.实现UITableView的数据源
Swift:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return dataArray.count}
Objective-C:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count;}
3.实现cell排序的代理方法
Swift:
// 设置 cell 是否允许移动func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { return true}// 移动 cell 时触发func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { // 移动cell之后更换数据数组里的循序 dataArray.exchangeObject(at: (sourceIndexPath as NSIndexPath).row, withObjectAt: (destinationIndexPath as NSIndexPath).row)}
Objective-C:
// 设置 cell 是否允许移动- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return true;}// 移动 cell 时触发- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { // 移动cell之后更换数据数组里的循序 [self.dataArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];}
4.开始编辑模式的代码:
Swift:
// 开启编辑模式tableView.isEditing = true// 结束编辑模式tableView.isEditing = false
Objective-C:
// 开启编辑模式self.tableView.editing = true;// 结束编辑模式self.tableView.editing = false;
2.UITableview的一些小细节
1.设置 cell 中间的间隔线
Swift
// 没有间隔线tableView.separatorStyle = .none// 默认的tableView.separatorStyle = .singleLine
Objective-C:
// 没有间隔线tableView.separatorStyle = UITableViewCellSeparatorStyleNone;// 默认的tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
2.设置右侧滑动进度条
Swift
// 显示或隐藏:true/falsetableView.showsVerticalScrollIndicator = true
Objective-C:
// 显示或隐藏:true/falsetableView.showsVerticalScrollIndicator = true;
3.去除UITableview底部空白的cell
如果UITableview中cell铺不满屏,底部会自动补充空白的cell,如图:
去除底部的空白cell,可以采取如下方式:
Swift
tableView.tableFooterView = UIView()
Objective-C:
tableView.tableFooterView = [[UIView alloc] init];
4.选中Cell时的样式
Swift
// 默认的,点击灰色cell.selectionStyle = .default// 去除选中时的颜色cell.selectionStyle = .none
Objective-C:
// 默认的,点击灰色cell.selectionStyle = UITableViewCellSelectionStyleDefault;// 去除选中时的颜色cell.selectionStyle = UITableViewCellSelectionStyleNone;
注:上面代码只是去掉了cell选中时的颜色,不会去掉点击触发的时间。
以上,就是UITableview的一些小细节。
UITableView的内容到此结束了。
1 0
- iOS UITableView(四)-Cell拖动更改排序
- IOS UITableView拖动排序功能
- <四>UITableView 自定义cell
- UITableView的Cell排序
- ios UITableview自定义cell
- iOS UITableView(四) 为tableView设置头尾视图,改变cell的宽度,cell的缩进
- IOS UITableView 移动自定义cell
- iOS开发 UITableView之cell
- IOS UITableview 的Cell 封装
- IOS-UITableView 及自定义cell
- IOS-UITableView 及自定义cell
- iOS UITableView(二)-自定义Cell
- iOS开发之高级视图—— UITableView(四)自定义Cell
- iOS UITableView的细致功能(滑动删除,拖动排序,添加行,搜索过滤)
- iOS cell排序
- iOS-TableView拖动Cell更换次序
- iOS-TableView拖动Cell更换次序
- ios 拖动重新排序
- Jenkins配置ant依赖问题
- 并发之痛 Thread,Goroutine,Actor
- HorizontalScrollView作为导航栏和HorizontalScrollView的滑动
- Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart
- leetcode题解-204. Count Primes
- iOS UITableView(四)-Cell拖动更改排序
- 几种遍历map的方法
- 如何使用反射
- Android自定义View之画笔与画布(2)
- kafka自学之路--zookeeper中存储结构
- linux中dig命令返回结果解释
- MFC GDI+基础
- spring-data-redis 使用
- 动态sql