//
// 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. Mybatis获取自增主键的值

    pojo: public class User { private Integer id; private String name; private String pwd; setter和getter ...

  2. 使用并行Foreach优化SqlSugarMapper

    最近在迁移公司导入导出项目时,发现导出速度特别慢,大概2K数据需要导出近半个小时,通过在程序各个地方埋点,最终定位到了Sqlsugar的Mapper中,随后通过并行Foreach单独抽出Mapper中 ...

  3. PathCopyCopy一键复制文件路径

    1.简介 PathCopyCopy一键复制文件/文件夹名称和路径, 右键文件或者文件夹,可以复制名称,路径和父目录等. 2.推荐理由 当我们想拷贝文件名或者文件路径时,简直是神器啊,实测真的好用. 还 ...

  4. 《手把手教你》系列技巧篇(五十四)-java+ selenium自动化测试-上传文件-中篇(详细教程)

    1.简介 在实际工作中,我们进行web自动化的时候,文件上传是很常见的操作,例如上传用户头像,上传身份证信息等.所以宏哥打算按上传文件的分类对其进行一下讲解和分享. 2.为什么selenium没有提供 ...

  5. python+appium运行提示找不到adb.exe “An unknown server-side error occurred while processing the command. Original error: Could not find 'adb.exe' in ["D:\\adt\\sdk;\\platform-tools\\adb.exe"”

    自己踩过的坑,不记下来就会忘掉,忘了就会不断的重复踩坑!! 重来在一台电脑上搭建了python的环境,在运行的时候,提示找不到adb.exe,看到这个问题我在想是不是我的环境变量配置有问题,我就去改了 ...

  6. spring的返回json数据给前端注意事项

    1. 记得加入SpringJSON解析包,否则spring无法将返回的pojo类解析成json数据 maven则加上下面的依赖包 <!-- SpringJSON解析包--> <jac ...

  7. HBase环境搭建(hbase1.2.5+zookeeper3.4.6)

    注:图片如果损坏,点击文章链接:https://www.toutiao.com/i6627857018461880836/ 系统版本,Hadoop已安装完成 Mysql安装完成 Hive版本 Sqoo ...

  8. 关于APP设计规范和一些图层命名

    首先,本人大学计算机专业出身,学过编程,工作的时候做过 产品经理,设计师,前端工程师,对工作的流程都有一些见解. 现在主攻前端工程师,做Web APP.今天收到设计师的设计稿,一看图层分类,这让我感觉 ...

  9. Kafka connector (kafka核心API)

    前言 Kafka Connect是一个用于将数据流输入和输出Kafka的框架.Confluent平台附带了几个内置connector,可以使用这些connector进行关系数据库或HDFS等常用系统到 ...

  10. Rancher Fleet使用教程

    官方文档: https://fleet.rancher.io/ https://github.com/rancher/fleet 博客截止日期为:20201204 当前官网版本为v0.3.0,但在实践 ...