本篇博客方便自己检索使用。资源链接

下面是制作效果图,点击删除按钮,就能将该cell删除:

下面是主要的代码:

#define KSUPER_TAG 20000
#define KDEFAU_TAG 10000 #import "WholeViewController.h"
#import "HJ_CELL_3.h"
#import "HJ_CELL_4.h"
#import "NULL_CELL.h"
#import "HRAdView.h"
#import "FrameMacro.h"
#import "ColorMacro.h"
#import "FontMacro.h" @interface WholeViewController ()
{
NSMutableArray *_dataSource;
UIView * _tabHead_View ; }
@end @implementation WholeViewController - (void)viewDidLoad {
[super viewDidLoad]; [self setTitle:@"全部"]; self.tableView.backgroundColor = K_SET_COLOR_VALUE(K_ROOT_BGC); // 假设有表头数据
[self createTableHeader]; // 设置无选择线
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; self.tableView.showsHorizontalScrollIndicator = NO;
self.tableView.showsVerticalScrollIndicator = NO; // 初始化数据源
_dataSource = [NSMutableArray arrayWithObjects:@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"", nil]; } // 创建表头
- (void)createTableHeader{ if (!_tabHead_View) { // 表头部分的View
_tabHead_View = [[UIView alloc] initWithFrame:CGRectMake(,, K_WIDTH, )]; _tabHead_View.backgroundColor = K_SET_COLOR_VALUE(K_ROOT_BGC); // 初始化广告控件
HRAdView *hdview = [[HRAdView alloc] initWithTitles:@[@"你有一笔支付订单30分钟后关闭",@"你有一笔支付订单60分钟后关闭",@"你有一笔支付订单90分钟后关闭"]];
hdview.time = ;
[hdview beginScroll];
hdview.backgroundColor = [UIColor whiteColor];
hdview.isHaveTouchEvent = YES;
hdview.clickAdBlock = ^(NSUInteger index){ NSLog(@"下标是 %ld",(unsigned long)index);
};
hdview.frame = CGRectMake(, , K_WIDTH, );
[_tabHead_View addSubview:hdview]; // 分割线 1
UIView *line_1 = [[UIView alloc] initWithFrame:CGRectMake(, , K_WIDTH, )];
[line_1 setBackgroundColor:K_SET_COLOR_VALUE(@"#dbdbdb")];
[_tabHead_View addSubview:line_1]; // 分割线 2
UIView *line_2 = [[UIView alloc] initWithFrame:CGRectMake(, , K_WIDTH, )];
[line_2 setBackgroundColor:K_SET_COLOR_VALUE(@"#dbdbdb")];
[_tabHead_View addSubview:line_2]; } self.tableView.tableHeaderView = _tabHead_View; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
if (self.isViewLoaded&&self.view.window) {
self.view = nil;
}
} #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_dataSource count];
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = nil; NSString *mask = _dataSource[indexPath.row]; if ([mask isEqualToString:@""]) { cell = (HJ_CELL_3*)[tableView dequeueReusableCellWithIdentifier:@"HJ_CELL_3" forIndexPath:indexPath]; if (nil == cell) { cell = (HJ_CELL_3*)[[[NSBundle mainBundle] loadNibNamed:@"HJ_CELL_3" owner:self options:nil] lastObject];
} ((HJ_CELL_3*)cell).block = ^(NSInteger statusNum){ if ( == statusNum) { // 执行删除任务
[self tableView:tableView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:indexPath];
}
};
}else if ([mask isEqualToString:@""]) { cell = (HJ_CELL_4*)[tableView dequeueReusableCellWithIdentifier:@"HJ_CELL_4" forIndexPath:indexPath]; if (nil == cell) { cell = (HJ_CELL_4*)[[[NSBundle mainBundle] loadNibNamed:@"HJ_CELL_4" owner:self options:nil] lastObject];
} ((HJ_CELL_4*)cell).block = ^(NSInteger statusNum){ if ( == statusNum) { // 执行删除任务
[self tableView:tableView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:indexPath];
}
}; }else { cell = (NULL_CELL*)[tableView dequeueReusableCellWithIdentifier:@"NULL_CELL" forIndexPath:indexPath]; if (nil == cell) { cell = (NULL_CELL*)[[[NSBundle mainBundle] loadNibNamed:@"NULL_CELL" owner:self options:nil] lastObject];
}
} return cell;
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *mask = _dataSource[indexPath.row]; if ([mask isEqualToString:@""]) { return ;
}else if ([mask isEqualToString:@""]) { return ;
}else { return ;
} return ; } // 删除某些行的方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source [_dataSource removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView reloadData]; } else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
} /*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/ /*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/ /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end

使用 StoryBoard 制作一个能够删除cell的TableView的更多相关文章

  1. 制作一个可以滑动操作的 Table View Cell

    本文转载至 https://github.com/nixzhu/dev-blog Apple 通过 iOS 7 的邮件(Mail)应用介绍了一种新的用户界面方案——向左滑动以显示一个有着多个操作的菜单 ...

  2. 使用 Swift 制作一个新闻通知中心插件(1)

    input[type="date"].form-control,.input-group-sm>input[type="date"].input-grou ...

  3. iOS自定义控件教程:制作一个可重用的旋钮

    当你的APP需要一些新功能时,自定义UI控件会十分有用,尤其是这些自定义控件可以在其他APP里面很好的重用.Colin Eberhart写过一篇很棒的介绍自定义UI控件的教程.这个教程涉及的是一个继承 ...

  4. Swift 制作一个新闻通知中心插件1

    使用 Swift 制作一个新闻通知中心插件(1) 随着 iOS 8 的发布,苹果为开发者们开放了很多新的 API,而在这些开放的接口中 通知中心插件 无疑是最显眼的一个.通知中心就不用过多介绍了,相信 ...

  5. ios学习-制作一个浏览图片的Demo

    一.项目要求:制作一个浏览图片的Demo,要求包含夜间模式,以及改变图片大小,能够显示不同的图片描述 二.开发步骤: 1.在storyboard上添加一个空白的View,然后添加”设置“按钮,添加im ...

  6. iOS学习——制作一个小型加法计算器

    一.项目要求:制作一个加法计算器.在第1个和第2个文本框中输入两个整数,然后点击“计算”按钮,可将计算结果显示在第3个文本框中. 二.开发步骤: 1.搭建UI界面 2.监听按钮的点击事件 3.获取文本 ...

  7. 使用sqlite3 有关tableview删除cell的问题

    在root页面,想要删除tableviewcell,是有一定顺序的 首先要删除 数据库sqlite3 中的数据,然后删除数组中的数据,最后删除cell 一般我们知道,删除cell要在删除数组数据之后, ...

  8. ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork 制作一个添加新闻功能

    本文将交大伙怎么集成ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork来制作一个新闻系统 先上截图: 添加页面如下: 下面来看代码部分 列表页如下: @ ...

  9. 用JS制作一个信息管理平台完整版

      前  言 JRedu 在之前的文章中,介绍了如何用JS制作一个实用的信息管理平台. 但是那样的平台功能过于简陋了,我们今天来继续完善一下. 首先我们回顾一下之前的内容.   1.JSON的基础知识 ...

随机推荐

  1. Linux/ visual studio 编译使用Poco

    1. 下载源码包.在POCO的官方网站下载最新的POCO源码包.http://pocoproject.org/download/index.html2.解压源码包.下载的文件名是“poco-1.6.0 ...

  2. 【java读书笔记】——java的异常处理

    程序在实际环境的执行过程中.安全成为须要首先考虑的重要因素之中的一个.这也是用户和程序猿最关心的问题.同一时候,Java语言健壮性也体如今了可以及时有效地处理程序中的错误.准确的说是Java的异常处理 ...

  3. 在eclipse中查找指定文件 [多种方法]

    在eclipse中查找指定文件   1.ctrl+h打开搜索界面 File Search: containing text填*,File name patterns填写hello.*,可以找到hell ...

  4. Ubuntu 16.04下配置Golang开发环境

    安装之前先要明白两个变量,后面介绍安装时,会用这两个变量 GOROOT   , 这是go的工作目录,比如 /home/[替换为你的用户名]/go/work GOPATH    , 这是go的安装目录, ...

  5. kubernetes故障现场一之Orphaned pod

    系列目录 问题描述:周五写字楼整体停电,周一再来的时候发现很多pod的状态都是Terminating,经排查是因为测试环境kubernetes集群中的有些节点是PC机,停电后需要手动开机才能起来.起来 ...

  6. MyBatis学习(二):与Spring整合(非注解方式配置MyBatis)

    搭建SpringMVC的-->传送门<-- 一.环境搭建: 目录结构: 引用的JAR包: 如果是Maven搭建的话,pom.xml的配置如下: <?xml version=" ...

  7. ffmpeg编码常见问题排查方法

    播放问题排查: 一旦我们遇到视频播放不了,第一件事,就是要找几个别的播放器也播放看看,做一下对比测试,或者对码流做一些基础分析,以便更好的定位问题的源头,而各个平台比较常见的播放/分析工具有如下几个: ...

  8. .Net——实现IConfigurationSectionHandler接口定义处理程序处理自定义节点

    除了使用.net里面提供的内置处理程序来处理我们的自定义节点外,我们还可以通过多种方法,来自己定义处理类处理我们的自定义节点,本文主要介绍通过实现IConfigurationSectionHandle ...

  9. kbmmw 5 的日志备份功能简介

    kbmmw 自从4.8.2 版本里增加了日志管理以后,随着版本升级,增加了很多功能,使用方法也有所改变. 功能也越来越强大. 今天说一下 kbmmw5 里面的日志备份,顺便演示一下新的使用方法. 我们 ...

  10. EasyPusher/EasyDarwin/EasyPlayer实现手机直播版本及效果整理

    EasyPusher手机直播 实现功能 最近很多EasyDarwin爱好者提出了手机移动端直播的功能需求,尤其是如何做出像映客这样能够快速出画面播放的效果,经过一段时间的移动端和服务端的优化,Easy ...