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

下面是制作效果图,点击删除按钮,就能将该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. loarocks install loadcaffe 失败

    loarocks install loadcaffe 失败 1.Error: Your user does not have write permissions in /home/zhangliang ...

  2. java web 站点头像上传处理 (springmvc +bootstrap+cropper)

    制作头像上传.请依据您的实际需求.改动代码,不全然正确.仅供參考! 前端页面设计使用bootstrap ,头像预览和剪裁工具使用cropper 后台使用springmvc. 如今来看前端的页面设计 前 ...

  3. python(31)- 模块练习

    1. 小程序:根据用户输入选择可以完成以下功能:     创意文件,如果路径不存在,创建文件夹后再创建文件     能够查看当前路径     在当前目录及其所有子目录下查找文件名包含指定字符串的文件 ...

  4. hdoj 5094 Maze 【BFS + 状态压缩】 【好多坑】

    Maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Sub ...

  5. ThinkPHP5 安装自定义模块

    安装官方给的demo,在build.php文件中 <?php // +-------------------------------------------------------------- ...

  6. 文件共享和使用 dup 函数创建新描述符的区别

    前言 文件共享是指同时打开一个文件 用 dup 函数能对指定文件描述符再创建一个新的描述符,且这个新的描述符和旧的描述符指向的是同一个文件. 这两种行为有什么区别呢?下面给出的两张文件系统的图形象的解 ...

  7. c# SQLServer导入大批量数据

    说来惭愧,关于批量导入数据,一直采用的是最原始的方式,一条一条插入,或者100条一块批量插入,这种方式,五十步笑百步,并没有明显的性能提升, 昨天在从别的库查询数据到DataTable内存中,然后插入 ...

  8. Cena使用

    打开cena,在工具-选项中,修改G++和GCC的编译命令.格式:[g++目录]g++.exe %s.cpp -o %s.exe [编译选项]例如以下命令使用刚安装的mingw4.8.1 g++编译, ...

  9. 用EasyClient开源项目采集Windows摄像头/麦克风的音视频进行RTSP直播

    EasyClient是EasyDarwin开源流媒体团队开发的一款功能丰富的开源PC客户端项目,目前支持Windows.Android版本,后续将支持ios版本,其中Windows版本的EasyCli ...

  10. win10获取注册表权限

    1.cmd中输入regedit打开注册表 2.在需要的注册表项中右键选择“权限”