使用 StoryBoard 制作一个能够删除cell的TableView
本篇博客方便自己检索使用。资源链接
下面是制作效果图,点击删除按钮,就能将该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的更多相关文章
- 制作一个可以滑动操作的 Table View Cell
本文转载至 https://github.com/nixzhu/dev-blog Apple 通过 iOS 7 的邮件(Mail)应用介绍了一种新的用户界面方案——向左滑动以显示一个有着多个操作的菜单 ...
- 使用 Swift 制作一个新闻通知中心插件(1)
input[type="date"].form-control,.input-group-sm>input[type="date"].input-grou ...
- iOS自定义控件教程:制作一个可重用的旋钮
当你的APP需要一些新功能时,自定义UI控件会十分有用,尤其是这些自定义控件可以在其他APP里面很好的重用.Colin Eberhart写过一篇很棒的介绍自定义UI控件的教程.这个教程涉及的是一个继承 ...
- Swift 制作一个新闻通知中心插件1
使用 Swift 制作一个新闻通知中心插件(1) 随着 iOS 8 的发布,苹果为开发者们开放了很多新的 API,而在这些开放的接口中 通知中心插件 无疑是最显眼的一个.通知中心就不用过多介绍了,相信 ...
- ios学习-制作一个浏览图片的Demo
一.项目要求:制作一个浏览图片的Demo,要求包含夜间模式,以及改变图片大小,能够显示不同的图片描述 二.开发步骤: 1.在storyboard上添加一个空白的View,然后添加”设置“按钮,添加im ...
- iOS学习——制作一个小型加法计算器
一.项目要求:制作一个加法计算器.在第1个和第2个文本框中输入两个整数,然后点击“计算”按钮,可将计算结果显示在第3个文本框中. 二.开发步骤: 1.搭建UI界面 2.监听按钮的点击事件 3.获取文本 ...
- 使用sqlite3 有关tableview删除cell的问题
在root页面,想要删除tableviewcell,是有一定顺序的 首先要删除 数据库sqlite3 中的数据,然后删除数组中的数据,最后删除cell 一般我们知道,删除cell要在删除数组数据之后, ...
- ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork 制作一个添加新闻功能
本文将交大伙怎么集成ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork来制作一个新闻系统 先上截图: 添加页面如下: 下面来看代码部分 列表页如下: @ ...
- 用JS制作一个信息管理平台完整版
前 言 JRedu 在之前的文章中,介绍了如何用JS制作一个实用的信息管理平台. 但是那样的平台功能过于简陋了,我们今天来继续完善一下. 首先我们回顾一下之前的内容. 1.JSON的基础知识 ...
随机推荐
- dos alias/cname address
diego@localhost sdk/include/Poco/Net]# dig b.wpss.cn ; <<>> DiG - <<>> b.wps ...
- 怎样把多个Android Project打包成一个APK
怎样把多个Android Project打包成一个APK(你的项目怎样引用其它项目). 怎样把多个android project 打包成一个apk呢,事实上原理是这种.一个主project引用其它的p ...
- HDU ACM 1073 Online Judge ->字符串水题
分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...
- UDIMM、RDIMM、SODIMM以及LRDIMM的区别
DIMM简介 DIMM(Dual Inline Memory Module,双列直插内存模块)与SIMM(single in-line memory module,单边接触内存模组)相当类似,不同的只 ...
- ubuntu 下的中文输入法的安装和配置- ibus
ibus输入法 Chinese语言包安装 首先需要给Ubuntu16.04安装Chinese语言包支持. 如上图点击其中的Install/Remove Languages…,这个对话框是通过syst ...
- android arcmenu
http://www.kankanews.com/ICkengine/archives/129193.shtml
- 【剑指Offer学习】【面试题62:序列化二叉树】
题目:请实现两个函数,分别用来序列化和反序列化二叉树. 解题思路 通过分析解决前面的面试题6.我们知道能够从前序遍历和中序遍历构造出一棵二叉树.受此启示.我们能够先把一棵二叉树序列化成一个前序遍历序列 ...
- mapper代理(十一)
原始 dao开发问题 1.dao接口实现类方法中存在大量模板方法,设想能否将这些代码提取出来,大大减轻程序员的工作量. 2.调用sqlsession方法时将statement的id硬编码了 3.调用s ...
- tomcat安装后问题解决
tomcat安装后问题解决 (1)tomcat无法正常启动的原因分析 JAVA_HOME 配置错误,或者没有配置 如果你的机器已经占有了8080 端口,则无法启动, 解决方法 (1) 你可以808 ...
- px dp 互转
/** * * px dip 转换 */ public class DensityUtil { /** * 根据手机分辨率 dip 转 px */ static public int dip2px(C ...