UITableView上的批量操作(系统方法)
来源:互联网 发布:福建卓知襄阳 编辑:程序博客网 时间:2024/06/09 20:15
//// TableViewController.m#import "TableViewController.h"#import "tgModel.h"#import "tgCell.h"@interface TableViewController ()/** 所有团购数据 */@property(nonatomic,strong) NSMutableArray *tgs;- (IBAction)clickedDeleteButton:(UIBarButtonItem *)sender;- (IBAction)clickedEditButton:(UIBarButtonItem *)sender;@end@implementation TableViewController- (NSMutableArray *)tgs{ if (_tgs == nil) { // 加载plist文件中的字典数组 NSString *path = [[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil]; NSArray *dictArray = [NSArray arrayWithContentsOfFile:path]; // 字典数组 -> 模型数组 NSMutableArray *arrayM = [NSMutableArray array]; for (NSDictionary *dict in dictArray) { tgModel *model = [tgModel tgWithDict:dict]; [arrayM addObject:model]; } _tgs = arrayM; } return _tgs;}- (void)viewDidLoad { [super viewDidLoad]; //允许在编辑模式进行多选操作 self.tableView.allowsMultipleSelectionDuringEditing = YES; self.navigationItem.rightBarButtonItem.title = nil;}#pragma mark - Table view data source- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.tgs.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ // 创建cell的过程封装到cell类中 tgCell *cell = [tgCell cellWithTableView:tableView]; //传递模型数据 cell.model = self.tgs[indexPath.row]; return cell;}#pragma mark - Table view delegate- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}- (IBAction)clickedDeleteButton:(UIBarButtonItem *)sender{ // 获取所有被选中的行 NSArray *indexPaths = [self.tableView indexPathsForSelectedRows]; //遍历所有的行号 NSMutableArray *deleteds = [NSMutableArray array]; for (NSIndexPath *path in indexPaths) { [deleteds addObject:self.tgs[path.row]]; } //删除模型数据 [self.tgs removeObjectsInArray:deleteds]; //刷新表格// [self.tableView reloadData]; //用下面这个方法有动画效果 [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:YES];}/** * 点击了导航栏左边按钮 */- (IBAction)clickedEditButton:(UIBarButtonItem *)sender{ //切换编辑模式 if (self.tableView.isEditing) { [self.tableView setEditing:NO animated:YES]; //更改leftBarButtonItem上的文字 self.navigationItem.leftBarButtonItem.title = @"编辑"; self.navigationItem.rightBarButtonItem.title = nil; }else{ [self.tableView setEditing:YES animated:YES]; //更改leftBarButtonItem上的文字 self.navigationItem.leftBarButtonItem.title = @"取消"; self.navigationItem.rightBarButtonItem.title = @"删除"; }}@end
0 0
- UITableView上的批量操作(系统方法)
- 0206-UITableView上的批量操作(自定义)
- iOS开发总结之UITableView表格数据的批量操作
- UITableview上gesture操作cell的技术实现
- jdbc批量操作的三种方法
- 关于在UITableView上添加PanGesture手势的方法
- 批量安装系统补丁的方法
- iOS开发总结之UITableView表格数据的批量操作2
- UITableView中行的操作
- UITableView中行的操作
- UITableView 中行的操作
- UITableView的一些操作
- UITableView 的操作
- UITableView的编辑操作
- linux 批量操作 方法
- ios之UITableView批量选中cell并实现删除cell的简单方法
- uitableview方法的说明
- UITableView方法的总结
- eclipse错误:Syntax error , 'for each' statements are only available if source level is 1.5
- NYOJ-420-p次方求和
- Zookeeper设置开启启动
- hdu 3605 Escape 二分图的多重匹配(匈牙利算法)
- yum search与install用法
- UITableView上的批量操作(系统方法)
- jxl对excel操作总结
- 基于PetShop的数据可视化网站(四):自定义成员资格
- untiy 3d ShaderLab第 1 章Shader(着色器)的概念和在 3D 游戏中的作用
- 1010. 一元多项式求导
- poj 2236 Wireless Network
- linux 下编译 boost 的笔记
- bzoj1601【Usaco2008 Oct】灌水
- Spider 之 下载连续的网页