python tableview双击排序_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 (){

NSMutableArray*productCategoryList ;

}@end

@implementationViewController- (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];

}returncell;

}#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值