//
// 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 滑动删除与排序功能的更多相关文章

  1. [转]ANDROID仿IOS微信滑动删除_SWIPELISTVIEW左滑删除例子

    转载:http://dwtedx.sinaapp.com/itshare_290.html 本例子实现了滑动删除ListView的Itemdemo的效果.大家都知道.这种创意是来源于IOS的.左滑删除 ...

  2. iOS UITableViewCell滑动删除

    一般我们使用列表的形式展现数据就会用到UITableView.在熟练掌握了用UITableView展示数据以后,开发过程中可能会遇到需要删除数据的需求,我们想实现在一行数据上划动一下,然后出现一个删除 ...

  3. IOS UITableViewUITableView小技巧--实现cell向左滑动删除,编辑等功能

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return Y ...

  4. iOS tableView自定义删除按钮

    // 自定义左滑显示编辑按钮 - (NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActio ...

  5. iOS tableView侧滑删除的第三方控件

    (到我的文件中,下载“tableview中cell测滑删除的第三方控件”),使用方法如下: 在tableView中的.m中,设置cell的方法上,事例代码如下,其中,EaseConversationC ...

  6. IOS TableView滑动不灵敏问题

    TableView的默认的不常用的属性,我们尽量不要去改,如下面标注的几个

  7. [Android-2A] -仿IOS微信滑动删除_SwipeListview左滑删除例子

    https://yunpan.cn/cueUIQkRafQrH (提取码:7ec1) 关于这样类似的例子网上的代码很多,最近发现这个例子里的代码在开发中会遇到一系列的问题.比如ListView的OnI ...

  8. iOS tableview滑动到底部自动加载,向上拽加载

    - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { CGPoint offset = aScrollView.contentOffset ...

  9. RecyclerView实现拖动排序和滑动删除功能

    RecyclerView 的拖动排序需要借助一下 ItemTouchHelper 这个类,ItemTouchHelper 类是 Google 提供的一个支持 RecyclerView 滑动和拖动的一个 ...

随机推荐

  1. 编写Java程序,以树形结构显示国家-直辖市/省/州信息

    返回本章节 返回作业目录 需求说明: 以树形结构显示国家-直辖市/省/州信息 实现思路: 创建显示树形结构的类Tree,在该类中定义Map类型的全局实例属性countryMap,该Map集合用于存放所 ...

  2. LDAP客户端安装

    安装环境: 10.43.159.7 客户端 使用ldap客户端验证登陆: 用户为10.43.159.9服务端上面创建的ldap:zdh1234 1.安装LDAP client认证需要的pam包 yum ...

  3. ActiveMQ基础教程(三):C#连接使用ActiveMQ消息队列

    接上一篇:ActiveMQ基础教程(二):安装与配置(单机与集群) 安装部署好集群环境:192.168.209.133:61616,192.168.209.134:61616,192.168.209. ...

  4. python使用String的Template进行参数动态替换

    1.前言: 之前使用string的find(),从指定的param里面查找,是否包含了某个字符,有的话,使用replace进行替换,一个接口的param要替换的参数少的话,使用这种方式,的确可行,如果 ...

  5. kubernetes (k8s) CKA认证之第二课:亲和性与 Pod 的调度

    手动调度一个 pod // cat manual-schedule.yaml apiVersion: v1 kind: Pod metadata: labels: run: pod-manual-sc ...

  6. 实验 7 : OpenDaylight 实验 —— Python 中的 REST API 调用

    实验 7 : OpenDaylight 实验 -- Python 中的 REST API 调用 一.实验 目的 对 Python 调用 OpenDaylight 的 REST API 方法有初步了解. ...

  7. 编写java程序压缩Linux本地目录

    注:图片如果损坏,点击文章链接:https://www.toutiao.com/i6809285459722633736/ 创建工程 使用maven工程 勾选,然后下一步 填写基本信息 注意改一下编码 ...

  8. Springboot整合Mybatis,连接多个数据库(Mysql+Oracle)

    maven依赖,需要注意的是mysql使用的版本 1 <dependencies> 2 <dependency> 3 <groupId>com.oracle.dat ...

  9. Tomcat部署启动时发生错误

    Tomcat启动后项目地址显示404:源服务器未能找到目标资源的表示或者是不愿公开一个已经存在的资源表示. 严重: ContainerBase.addChild: start: org.apache. ...

  10. 【失败的经验】在linux下编译opencv for android

    cd /home/ahfu#选择opencv 3.4.6版本来编译wget https://github.com/opencv/opencv/archive/3.4.6.tar.gztar -zxvf ...