自定义UITableViewCell 的delete按钮
自定义UITableViewCell上的delete按钮
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
//通过UITableViewDelegate方法可以实现删除 tableview中某一行 //滑动删除-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ NSUInteger row = [indexPath row]; [bookInforemoveObjectAtIndex:row];//bookInfo为当前table中显示的array [tableView deleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationLeft];}/*此时删除按钮为Delete,如果想显示为“删除” 中文的话,则需要实现UITableViewDelegate中的- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath方法*/- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{ return @"删除"; } //或者,最简单的方式,将plist中的Localization native development region改为China即可//这只是让默认的Delete按钮显示成了中文的删除按钮而已,如果想将这个删除按钮换成其他图片形式的,怎么办呢?-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *RootViewControllerCell = @"RootViewControllerCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RootViewControllerCell]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell]autorelease]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal]; [button setFrame:CGRectMake(280, 10, 30, 30)]; [button addTarget:self action:@selector(del:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:button]; } cell.textLabel.text = [array objectAtIndex:[indexPath row]]; cell.tag = [indexPath row]; NSArray *subviews = [cell.contentView subviews]; for(id view in subviews) { if([view isKindOfClass:[UIButton class]]) { [view setTag:[indexPath row]]; [cell.contentView bringSubviewToFront:view]; } } return cell; } -(void)del:(UIButton *)button { NSArray *visiblecells = [self.table visibleCells]; for(UITableViewCell *cell in visiblecells) { if(cell.tag == button.tag) { [array removeObjectAtIndex:[cell tag]]; [table reloadData]; break; } } } |
自定义UITableViewCell 的delete按钮的更多相关文章
- 如何得到自定义UITableViewCell中的按钮所在的cell的indexPath.row
在自定义UITableViewCell中创建了一个按钮. 想在点击该按钮时知道该按钮所在的cell在TableView中的行数.就是cell的 indexPath.row两种方法都很好.-(IBAct ...
- 自定义 UITableViewCell 的 accessory 样式
对于 UITableViewCell 而言,其 accessoryType属性有4种取值: UITableViewCellAccessoryNone, UITableViewCellAccessory ...
- UITableViewCell上的按钮点击事件处理
转自: http://www.aichengxu.com/view/42871 UITableViewCell上的按钮点击事件处理,有需要的朋友可以参考下. 今天突然做项目的时候,又遇到处理自定义的 ...
- 自定义UITableViewCell实现左滑动多菜单功能LeftSwipe
今天愚人节,小伙们,愚人节快乐! 实现一个小功能,滑动菜单,显示隐藏的功能菜单, 先上图: 这里尝试用了下使用三个方式来实现了这个功能: 1.使用自定义UI ...
- 【转】自定义UITableViewCell(registerNib: 与 registerClass: 的区别)
自定义UITableViewCell大致有两类方法: 使用nib 1.xib中指定cell的Class为自定义cell类型(注意不是设置File's Owner的class) 2.调用 tableVi ...
- ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局
本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局 一.项目文件结构和plist文件 二.实现效果 三.代码示例 1.没有使用配套的类,而是直接使用xib文 ...
- 新手教程之使用Xib自定义UITableViewCell
新手教程之使用Xib自定义UITableViewCell 前言 首先:什么是UITableView?看图 其次:什么是cell? 然后:为什么要自定cell,UITableView不是自带的有cell ...
- 【转】iOS 通过xib自定义UITableViewCell【原创】
原文网址:http://blog.it985.com/9683.html 在使用tableView的时候,如果cell的布局过于复杂,通过代码搭建的话不够直观.并且要不停的调整位置,字体什么的.这时, ...
随机推荐
- MySQL的五种日期和时间类型
MySQl中有多种表示日期和时间的数据类型.其中YEAR表示年份,DATE表示日期,TIME表示时间,DATETIME和TIMESTAMP表示日期和实践.它们的对比如下:YEAR ,字节数 ...
- Codeforces Round #350 (Div. 2) B. Game of Robots 水题
B. Game of Robots 题目连接: http://www.codeforces.com/contest/670/problem/B Description In late autumn e ...
- 指针式压力表自动读数:Auto Read the Value of Manometer
指针式压力表的自动读数,用摄像头对准压力计,然后实时自动地读取压力计的读数.视频效果如下视频所示,红色数字为识别到的指针读数.
- 腾讯的网站是如何检测到你的 QQ 已经登录?
在 QQ 已经登录的情况下,手动输入网址打开 QQ 邮箱 或者 QQ 空间 等腾讯网站,可以看到网页已经检测到本地 QQ 客户端已经登录,于是用户可以很方便地一键登录网站而不必再输入用户名密码. 这实 ...
- gridview DataFormatString 属性设置须知
设置 DataFormatString 进行格式化数据时默认情况下是不会起作用的还有设置HtmlEncode = "false" 具体为什么?以下几点1. 在GridView中的a ...
- vim segment fault when i upgrade to macOS Mojave 103_PollServerReady
系统升级到 macOS Mojave, vim插件YouCompleteMe出错. Vim: Caught deadly signal SEGV Error detected while proces ...
- SPOJ 10628. Count on a tree (树上第k大,LCA+主席树)
10628. Count on a tree Problem code: COT You are given a tree with N nodes.The tree nodes are number ...
- 5V and 3V Level Translators
http://www.daycounter.com/Circuits/Level-Translators/Level-Translators.phtml Interfacing 5V and 3V l ...
- 配置tomcat让shtml嵌套文件显示
之前,我知道tomcat可以直接解析shtml文件,在浏览器中显示效果来,后来由于需求发生改变,比如说 在做静态化生成的时候一个网站的头部和底部都是一样的,如果每个页面都生成一次,显然很浪费时间,所有 ...
- AMD64 Instruction-Level Debugging With dbx
http://www.oracle.com/technetwork/server-storage/solarisstudio/documentation/amd64-dbx-364568.html A ...