tableView左滑删除功能

摘要:
实现三个代理方法-(NSString*)tableView:(UITableView*)tableViewtitleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexPath{return@“delete”;}-(UITableView CellEditingStyle)tableView:(UITableView*)table

实现三个代理方法即可

tableView左滑删除功能第1张

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    return @"删除";
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{   if (!indexPath.section) return UITableViewCellEditingStyleNone; // 第一组家和公司不提供左滑删除功能
    return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
        [self.commonPlaceArray removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:@[indexPath]
                              withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadData];
    }
}

上面说漏了一点,就是有个代理方法是开启允许进入编辑状态的,这样才可以进行左滑或者添加的其他操作,注意当你左滑后,没有把这个cell滑回去,这时候如果你在返回上一个页面可能会崩溃,这个时候你需要在viewWillDisappear方法中将这个编辑状态置为NO,好的,现在终于操作流畅了。

免责声明:文章转载自《tableView左滑删除功能》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Python利用openpyxl带格式统计数据(2)- 处理mysql数据Raid 技术简介下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

iOS中上拉加载下拉刷新之MJRefresh

1.导入到自己的工程中,如果是非ACR,则需要-fno-objc-arc,如果是arc就不用管了。 一般的刷新都是基于UIScrollView的,因为能拖拽的view一般都是继承于UIScrollView。 2.#import “MJRefresh.h”   这个可以直接加载.m中 然后.h文件中: 1 #import <UIKit/UIKit.h&...

tableView里选中一行cell其它不选中的方法

方法1: #pragma mark--选中状态 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { GASSelectNextTableViewCell *cell = (GASSelectNextTableViewCell...

iOS UIKit:TableView之编辑模式(3)

一般table view有编辑模式和正常模式,当table view进入编辑模式时,会在row的左边显示编辑和重排控件,如图 42所示的编辑模式时的控件布局;左边的editing control有表 61的两种图标。 表 61 table view编辑控件 图标 描述 Deletion控件 Insertion控件 若ta...

ios tableview 滑动到底部

tableview滑动到底部,根据页面不同 可以有两种方法 第一种: 一般样式的tableview 没有头和尾的 #pragma mark - 滑到最底部 - (void)scrollTableToFoot:(BOOL)animated { NSInteger s = [self.tableView numberOfSections]; //有多少组 i...

iOS 数组越界 Crash处理经验

我们先来看看有可能会出现的数组越界Crash的地方; - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { WelfareItem *item = [_datasourceArray objectAtIndex:in...

IOS UITableView

一、自定义TableViewCell 1. 创建Cocoa Touch Class文件,同时,生成xib文件。 2. 设置xib文件对象的基类    3. 拖拽控件(UIImageView、UILabel),并且设置其位置和大小。    4. 用拖拽方式创建控件属性代码,使用Alt+鼠标左键同时打开xib文件及基类*.h文件。再用Control+鼠标左键,...