单元格的多选删除

 

 
#import "ViewController.h"
 @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>@property(retain)UITableView* tableView;@property(retain)NSMutableArray* dataSource;@property(retain)NSMutableArray* removeData;@property(assign)BOOL isEdit;
@end
 
@implementation
ViewController
 
- (
void
)viewDidLoad {
    [
super viewDidLoad
];
   
self.view.backgroundColor=[UIColor cyanColor
];
   
//防止下滑
 
   
self.automaticallyAdjustsScrollViewInsets=NO
;
   
//申请内存
 
   
_dataSource=[NSMutableArray new
];
   
_removeData=[NSMutableArray new
];
   
//创建表格视图
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) style:UITableViewStylePlain];
    //添加   
   
   
//NSMutableArray* arr=[NSMutableArray new];
 
       
for (int j=0; j<15
; j++) {
          
               
NSString* str=[NSString stringWithFormat:@"男%d号"
,j];
               
//[arr addObject:str];
 
            [
_dataSource addObject
:str];
        }
       
//显示表格的编辑按钮
 
   
self.navigationItem.rightBarButtonItem=self.editButtonItem
;
   
//表格视图代理
 
   
_tableView.delegate=self
;
   
//数据源代理
 
   
_tableView.dataSource=self
;
    [
self.view addSubview:_tableView
];
 
}
//实现控制表格的编辑状态开启或者关闭的方法
 
-(
void)setEditing:(BOOL)editing animated:(BOOL
)animated
{
    [
super setEditing:editing animated
:animated];
   
//取非
 
   
_isEdit=!_isEdit
;
   
//开启表格的标记状态
 
    [
_tableView setEditing:_isEdit animated:YES
];
   
}
-(
UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath
*)indexPath
{
   
return UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert
;
}
-(
UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
   
//
 
   
static NSString* str=@"cell"
;
   
NSLog(@"单元格"
);
   
UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier
:str];
   
//如果不存在就创建
 
   
if (cell==nil
) {
       
//创建单元格
 
        cell=[[
UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier
:str];
        }
   
//设置标题  因为标题在数据源中的小数组里面,所以必须先取到小数组  才能取到真正的标题内容  小数组的获取可以通过区的索引值来获取  标题可以通过行的索引值获取  也就是indexPath indexPath里面包含了当前组的索引值和当前行的索引值  indexPath.section 是当前组的索引值  indexPath.row 当前行的索引值
 
    cell.
textLabel.text=_dataSource[indexPath.row
];
   
      
return
cell;
}
 
-(
NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
)section
{
   
NSLog(@"行"
);
   
return [_dataSource count
];
}
//返回每个区尾部视图的高度
 
-(
CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger
)section
{
   
return 30
;
}
-(
UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger
)section
{
   
UIButton* btn=[UIButton buttonWithType:UIButtonTypeCustom
];
    btn.
frame=CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30
);
    btn.
backgroundColor=[UIColor cyanColor
];
    [btn
addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside
];
    [btn
setTitle:@"Delete" forState:UIControlStateNormal
];
   
return
btn;
}
-(
void)btnAction:(UIButton
*)sender
{
   
NSLog(@" +++++"
);
   
//如果进入编辑状态才可以删除
 
   
if (_isEdit==YES
) {
       
//吧数据源内_removeData里的数据全部清空
 
        [
_dataSource removeObjectsInArray:_removeData
];
       
//清空上次选中行的数据
 
        [
_removeData removeAllObjects
];
       
//当表格的数据源发生变化时 reloadData  向表格发送消息  可以重新加载表格视图
 
        [
_tableView reloadData
];
    }
}
-(
void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath
*)indexPath
{
   
//先获取被选中行的数据
 
   
NSString* obj=[_dataSource objectAtIndex:indexPath.row
];
   
//存到 数组中
 
    [
_removeData addObject
:obj];
}
//当用户又一次点击某一行  则之前的行会调用这个方法(反选行操作)
 
-(
void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath
*)indexPath
{
   
//参数 indexPath 存放的就是上次被选中的行的信息
 
   
//移除上次选中该行进行 _removeData 中的信息
 
   
NSString* str=[_dataSource objectAtIndex:indexPath.row
];
   
if ([_removeData containsObject
:str]) {
        [
_removeData removeObject
:str];
    }
}
- (
void
)didReceiveMemoryWarning {
    [
super didReceiveMemoryWarning
];
   
// Dispose of any resources that can be recreated.
 
}
 
@end

---恢复内容结束---

 
#import "ViewController.h"
 @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>@property(retain)UITableView* tableView;@property(retain)NSMutableArray* dataSource;@property(retain)NSMutableArray* removeData;@property(assign)BOOL isEdit;
@end
 
@implementation
ViewController
 
- (
void
)viewDidLoad {
    [
super viewDidLoad
];
   
self.view.backgroundColor=[UIColor cyanColor
];
   
//防止下滑
 
   
self.automaticallyAdjustsScrollViewInsets=NO
;
   
//申请内存
 
   
_dataSource=[NSMutableArray new
];
   
_removeData=[NSMutableArray new
];
   
//创建表格视图
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) style:UITableViewStylePlain];
    //添加   
   
   
//NSMutableArray* arr=[NSMutableArray new];
 
       
for (int j=0; j<15
; j++) {
          
               
NSString* str=[NSString stringWithFormat:@"男%d号"
,j];
               
//[arr addObject:str];
 
            [
_dataSource addObject
:str];
        }
       
//显示表格的编辑按钮
 
   
self.navigationItem.rightBarButtonItem=self.editButtonItem
;
   
//表格视图代理
 
   
_tableView.delegate=self
;
   
//数据源代理
 
   
_tableView.dataSource=self
;
    [
self.view addSubview:_tableView
];
 
}
//实现控制表格的编辑状态开启或者关闭的方法
 
-(
void)setEditing:(BOOL)editing animated:(BOOL
)animated
{
    [
super setEditing:editing animated
:animated];
   
//取非
 
   
_isEdit=!_isEdit
;
   
//开启表格的标记状态
 
    [
_tableView setEditing:_isEdit animated:YES
];
   
}
-(
UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath
*)indexPath
{
   
return UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert
;
}
-(
UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
   
//
 
   
static NSString* str=@"cell"
;
   
NSLog(@"单元格"
);
   
UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier
:str];
   
//如果不存在就创建
 
   
if (cell==nil
) {
       
//创建单元格
 
        cell=[[
UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier
:str];
        }
   
//设置标题  因为标题在数据源中的小数组里面,所以必须先取到小数组  才能取到真正的标题内容  小数组的获取可以通过区的索引值来获取  标题可以通过行的索引值获取  也就是indexPath indexPath里面包含了当前组的索引值和当前行的索引值  indexPath.section 是当前组的索引值  indexPath.row 当前行的索引值
 
    cell.
textLabel.text=_dataSource[indexPath.row
];
   
      
return
cell;
}
 
-(
NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
)section
{
   
NSLog(@"行"
);
   
return [_dataSource count
];
}
//返回每个区尾部视图的高度
 
-(
CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger
)section
{
   
return 30
;
}
-(
UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger
)section
{
   
UIButton* btn=[UIButton buttonWithType:UIButtonTypeCustom
];
    btn.
frame=CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30
);
    btn.
backgroundColor=[UIColor cyanColor
];
    [btn
addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside
];
    [btn
setTitle:@"Delete" forState:UIControlStateNormal
];
   
return
btn;
}
-(
void)btnAction:(UIButton
*)sender
{
   
NSLog(@" +++++"
);
   
//如果进入编辑状态才可以删除
 
   
if (_isEdit==YES
) {
       
//吧数据源内_removeData里的数据全部清空
 
        [
_dataSource removeObjectsInArray:_removeData
];
       
//清空上次选中行的数据
 
        [
_removeData removeAllObjects
];
       
//当表格的数据源发生变化时 reloadData  向表格发送消息  可以重新加载表格视图
 
        [
_tableView reloadData
];
    }
}
-(
void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath
*)indexPath
{
   
//先获取被选中行的数据
 
   
NSString* obj=[_dataSource objectAtIndex:indexPath.row
];
   
//存到 数组中
 
    [
_removeData addObject
:obj];
}
//当用户又一次点击某一行  则之前的行会调用这个方法(反选行操作)
 
-(
void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath
*)indexPath
{
   
//参数 indexPath 存放的就是上次被选中的行的信息
 
   
//移除上次选中该行进行 _removeData 中的信息
 
   
NSString* str=[_dataSource objectAtIndex:indexPath.row
];
   
if ([_removeData containsObject
:str]) {
        [
_removeData removeObject
:str];
    }
}
- (
void
)didReceiveMemoryWarning {
    [
super didReceiveMemoryWarning
];
   
// Dispose of any resources that can be recreated.
 
}
 
@end

转载于:https://www.cnblogs.com/longyongping/p/7263506.html

本项目是一个基于SSM(Spring+SpringMVC+MyBatis)后端框架与Vue.js前端框架开发的疫情居家办公系统。该系统旨在为居家办公的员工提供一个高效、便捷的工作环境,同时帮助企业更好地管理远程工作流程。项目包含了完整的数据库设计、前后端代码实现以及详细的文档说明,非常适合计算机相关专业的毕设学生和需要进行项目实战练习的Java学习者。 系统的核心功能包括用户管理、任务分配、进度跟踪、文件共享和在线沟通等。用户管理模块允许管理员创建和管理用户账户,分配不同的权限。任务分配模块使项目经理能够轻松地分配任务给团队成员,并设置截止日期。进度跟踪模块允许员工实时更新他们的工作状态,确保项目按计划进行。文件共享模块提供了一个安全的平台,让团队成员可以共享和协作处理文档。在线沟通模块则支持即时消息和视频会议,以增强团队之间的沟通效率。 技术栈方面,后端采用了Spring框架来管理业务逻辑,SpringMVC用于构建Web应用程序,MyBatis作为ORM框架简化数据库操作。前端则使用Vue.js来实现动态用户界面,搭配Vue Router进行页面导航,以及Vuex进行状态管理。数据库选用MySQL,确保数据的安全性和可靠性。 该项目不仅提供了一个完整的技术实现示例,还为开发者留下了扩展和改进的空间,可以根据实际需求添加新功能或优化现有功能。
本项目是一个基于SSM(Spring+SpringMVC+MyBatis)后端框架与Vue.js前端框架开发的网上球鞋竞拍系统。该项目旨在为球鞋爱好者提供一个便捷、高效的在线竞拍平台,用户可以在此平台上浏览、搜索、竞拍心仪的球鞋,并参与到各种有趣的竞拍活动中。 系统的主要功能包括用户注册登录、球鞋信息展示、竞拍活动创建与管理、实时竞拍以及交易安全保障等。用户可以通过注册账号后,浏览平台上发布的各类球鞋信息,包括品牌、型号、颜色、尺码以及当前竞拍状态等。系统支持用户创建和管理自己的竞拍活动,设定竞拍规则和时间,同时提供实时竞拍功能,确保公平、透明的交易过程。 在技术实现上,后端采用SSM框架进行开发,Spring负责业务逻辑层,SpringMVC处理Web请求,MyBatis进行数据库操作,保证了系统的稳定性和扩展性。前端则使用Vue.js框架,结合Axios进行数据请求,实现了前后端分离,提高了开发效率和用户体验。 数据库设计方面,系统采用了MySQL数据库,存储用户信息、球鞋信息、竞拍活动等数据,确保数据的安全性和完整性。此外,项目还包含了详细的文档资料,包括需求分析、系统设计、数据库设计以及测试报告等,为项目的实施和维护提供了有力的支持。 该项目不仅适合作为计算机相关专业学生的毕业设计题目,也适合Java学习者进行实战练习,通过在此基础上进行功能扩展和改进,可以进一步提升编程技能和项目管理能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值