IOS tableView 滑动删除与排序功能
//
// ViewController.m
// 0429
//
// Created by apple on 15/4/29.
// Copyright (c) 2015年 gense. All rights reserved.
// #import "ViewController.h"
#import "ProductCategory.h" @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSMutableArray * productCategoryList ;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; //从配置文件中初始化商品类型信息
[self initProudctCategory]; } #pragma mark 从配置文件中初始化商品类型信息
- (void) initProudctCategory
{
//读取参数文件
NSString * paramPath = [[NSBundle mainBundle] pathForResource:@"shops.plist" ofType:nil];
NSArray * dataArr = [NSArray arrayWithContentsOfFile:paramPath]; productCategoryList = [NSMutableArray arrayWithCapacity:10]; //遍历plist文件
[dataArr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[productCategoryList addObject: [ProductCategory productCategoryWithName:obj[@"name"] andDesc:obj[@"desc"] icon:obj[@"icon"]]];
}]; } #pragma mark tableviewDeleage 总共有多少行记录
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [productCategoryList count];
} #pragma mark 实例化每行cell
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * cellIdentified = @"productCategoryTableViewCell"; //从缓存中加载可用的cell
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentified]; if(cell == nil) //从缓存在未拿到合适的cell
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentified]; } //设置cell中的属性
cell.textLabel.text = [productCategoryList[indexPath.row] name];
cell.detailTextLabel.text = [productCategoryList[indexPath.row] desc]; cell.imageView.image = [UIImage imageNamed:[productCategoryList[indexPath.row] icon]]; if([productCategoryList[indexPath.row] isSelected])
{
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}
else{
[cell setAccessoryType:UITableViewCellAccessoryNone];
} return cell;
} #pragma mark 设置tableview每行的高度 - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50.0;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[productCategoryList[indexPath.row] setIsSelected: ![productCategoryList[indexPath.row] isSelected ]]; [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } #pragma mark 滑动删除
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(UITableViewCellEditingStyleDelete == editingStyle)
{
[productCategoryList removeObjectAtIndex:indexPath.row]; //[_productCategoryTV reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop]; [_productCategoryTV deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
}
} #pragma mark 拖动排序
-(void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
ProductCategory * p = productCategoryList[sourceIndexPath.row]; [productCategoryList removeObject:p]; [productCategoryList insertObject:p atIndex:destinationIndexPath.row]; } #pragma mark 删除选中的数据
- (IBAction)trashItemClick:(id)sender
{
// NSMutableArray * deleteArr = [NSMutableArray arrayWithCapacity:10];
// NSMutableArray * indexPathArr = [NSMutableArray arrayWithCapacity:10 ];
//
// [productCategoryList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// if([obj isSelected])
// {
// [deleteArr addObject:obj];
// [indexPathArr addObject:[NSIndexPath indexPathForItem:idx inSection:0]];
// }
// }];
//
// [productCategoryList removeObjectsInArray:deleteArr];
//
// //tableview reload
// [_productCategoryTV deleteRowsAtIndexPaths:indexPathArr withRowAnimation:UITableViewRowAnimationMiddle];
_productCategoryTV.editing = !_productCategoryTV.isEditing; }
@end
IOS tableView 滑动删除与排序功能的更多相关文章
- [转]ANDROID仿IOS微信滑动删除_SWIPELISTVIEW左滑删除例子
转载:http://dwtedx.sinaapp.com/itshare_290.html 本例子实现了滑动删除ListView的Itemdemo的效果.大家都知道.这种创意是来源于IOS的.左滑删除 ...
- iOS UITableViewCell滑动删除
一般我们使用列表的形式展现数据就会用到UITableView.在熟练掌握了用UITableView展示数据以后,开发过程中可能会遇到需要删除数据的需求,我们想实现在一行数据上划动一下,然后出现一个删除 ...
- IOS UITableViewUITableView小技巧--实现cell向左滑动删除,编辑等功能
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return Y ...
- iOS tableView自定义删除按钮
// 自定义左滑显示编辑按钮 - (NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActio ...
- iOS tableView侧滑删除的第三方控件
(到我的文件中,下载“tableview中cell测滑删除的第三方控件”),使用方法如下: 在tableView中的.m中,设置cell的方法上,事例代码如下,其中,EaseConversationC ...
- IOS TableView滑动不灵敏问题
TableView的默认的不常用的属性,我们尽量不要去改,如下面标注的几个
- [Android-2A] -仿IOS微信滑动删除_SwipeListview左滑删除例子
https://yunpan.cn/cueUIQkRafQrH (提取码:7ec1) 关于这样类似的例子网上的代码很多,最近发现这个例子里的代码在开发中会遇到一系列的问题.比如ListView的OnI ...
- iOS tableview滑动到底部自动加载,向上拽加载
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView { CGPoint offset = aScrollView.contentOffset ...
- RecyclerView实现拖动排序和滑动删除功能
RecyclerView 的拖动排序需要借助一下 ItemTouchHelper 这个类,ItemTouchHelper 类是 Google 提供的一个支持 RecyclerView 滑动和拖动的一个 ...
随机推荐
- Java面向对象笔记 • 【第8章 内部类和泛型】
全部章节 >>>> 本章目录 8.1 内部类 8.1.1 内部类概述 8.1.2 内部类使用 8.1.3 实践练习 8.2 静态内部类 8.2.1 静态内部类的实现 8.2 ...
- Swoole 中使用 HTTP 异步服务器、HTTP 协程服务器
HTTP 异步风格服务器 # http_server.php $http = new Swoole\Http\Server("0.0.0.0", 9501); // 设置服务器运行 ...
- 『德不孤』Pytest框架 — 1、Pytest测试框架介绍
目录 1.什么是单元测试框架 2.单元测试框架主要做什么 3.单元测试框架和自动化测试框架有什么关系 4.Pytest测试框架说明 5.Pytest框架和Unittest框架区别 (1)Unittes ...
- 初识python 之 离线搭建pyhive环境(含python3安装)
系统版本: centos6.5 python版本:python3.6.8 相关包存放目录:software 注意:以下操作需要用到root权限 安装python3 root操作 cd /lzh/sof ...
- Docker_部署本地镜像仓库(6)
在部署本地镜像仓库之前,需要在主机上安装Docker.本地镜像仓库是registry镜像的一个实例,在Docker中运行. 1.创建本地镜像仓库服务 $ docker run -d -p 4000:5 ...
- Selenium_元素定位(2)
Selenium操作页面上的文本输入框.按钮.单选框.复选框等,凡是能在页面显示的任何元素都需要先对元素进行定位. Selenium提供了以下方法来定位页面中元素: find_element_by_i ...
- mybatis-plus实现多表联查
一.方法一 1.在pojo模块下新建一个VO 包路径用于提供页面展示所需的数据 2.在vo包下新建EmployInfo类,此类继承了Employees类,再把Dept类的数据复制过来 3.在Dao层中 ...
- 痞子衡嵌入式:我入选了2021年度与非网(eefocus)星选创作者Top10
本周二「与非网」一个美女运营小姐姐加痞子衡微信,告知痞子衡评上了一个奖,让痞子衡把收件地址告诉她,她把证书寄过来. 昨天痞子衡收到了快递,拆开一看,原来是被评上了 与非网 2021 年度创作者,这个证 ...
- host解析
首先了解一下什么是hosts文件: hosts是一个没有扩展名的系统文件,可以用记事本等文本编辑工具打开,起作用就是将一些常用的"网址域名"与其对应的"IP地址" ...
- 【白话科普】《逆局》最终 boss 隐藏自己的方式是?
二狗子最近在看一个很火的电视剧<逆局>.作为一部悬疑犯罪剧,剧中多个案件交织并进,悬念和转折拉满,让狗子看的直呼过瘾.特别最后一幕,杨副座和主角团同时对 U 盘中的关键证据"器官 ...