IOS基础18之UITableView--编辑模式:添加、删除、移动

 

#pragma mark - 生命周期方法
 
#pragma mark - 数据源方法  (其中有两个必要的方法)

第一个方法:告诉这个tableView有多少行

- (NSInteger)tableView :(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{}

第二个方法:告诉某一行显示什么数据

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}

 

------------------------------------------------------------------------------------------------------------------------

#pragma mark - 代理方法
 
1>>#pragma mark 设置每行的高度
 
2>>#pragma mark 提交编辑操作时会调用这个方法(删除、添加)
---->删除操作
2.1.删除数据
2.2.更新UITableView UI 界面 ---有两种方法,任选一种即可

2.2.1> [tableView reloadData];//没有动画效果

2.2.2> [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]

        withRowAnimation:UITableViewRowAnimationAutomatic];//有动画效果

---->添加操作
2.1.添加数据
2.2.更新UI界面

[tableView insertRowsAtIndexPaths.....] 

 

3>>#pargma mark 决定tableView的编辑模式
UITableViewCellEditingStyle // 当前的编辑模式
4>>#pragma mark 只有实现这个方法,编辑模式中允许移动Cell
moveRowAtIndexPath:(NSIndexPath *)sourceIndexpath......

 

 --------------------------------------------------------------------------------------------------

#pragma mark - 公共方法

  #pragma mark 删除数据

  1、开启编辑模式

    self.tableViewl.editing = YES;//没有动画效果

    [self.tableView setEditing:YES animated:YES];有动画效果

  2、开户\关闭编辑模式

    BOOL isEditing = self.tableView.isEditing;

    [self.tableVeiw setEditing:!isEditing animated:YES];

转载于:https://www.cnblogs.com/iPhone-6/p/3325573.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值