自定义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( 2 8 0 , 1 0 , 3 0 , 3 0 )]; [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的布局过于复杂,通过代码搭建的话不够直观.并且要不停的调整位置,字体什么的.这时, ...
随机推荐
- chrome --headless --disable-gpu --dump-dom http://www.python.org
Driving Headless Chrome with Python:Python chrome --headless --disable-gpu --dump-dom http://www.pyt ...
- Polly简介 — 1. 故障处理策略
Polly 是 .Net 下的一套瞬时故障处理及恢复的函式库,可让开发者以fluent及线程安全的方式来应用诸如Retry.Circuit Breaker.Timeout.Bulkhead Isola ...
- My simplified pickit2 clone
http://simon.derr.free.fr/site/spip/spip.php?article11 This is a description of my very simplified h ...
- DM6446开发攻略:UBOOT-2009.03移植及nand flash烧写
有关DAVINCI U-BOOT的移植,以前写过一篇u-boot-1.3.4(2008年的),其实和这个u-boot-2009.03差别不大,只不过这个u-boot-2009.03是从TI的网站上下载 ...
- [android]ShareSDK——内容分享和短信验证
前言 新版本号ShareSDK的分享和短信验证,按官网的文档,都须要加入一个<Activity></Activity>标签,而分享和短息验证的这个标签内容都一样.会冲突. 解决 ...
- Writable atomic property '***' cannot pair a synthesized setter/getter with a user defined
1. warning: Semantic Issue: Writable atomic property 'number' cannot pair a synthesized setter/gette ...
- iptables只允许指定ip地址访问指定端口
首先,清除所有预设置 iptables -F#清除预设表filter中的所有规则链的规则 iptables -X#清除预设表filter中使用者自定链中的规则 其次,设置只允许指定ip地址访问指定端口 ...
- Java中List效率的比较
Java Collections Framework(JCF) 是Java SE中一个基本的类集,几乎所有的项目都会用到,其中的List 则是JCF中最最常用的一个接口.围绕List 接口,有很多实现 ...
- 推荐Java程序员阅读的书籍(转)
作为Java程序员来说,最痛苦的事情莫过于可以选择的范围太广,可以读的书太多,往往容易无所适从.我想就我自己读过的技术书籍中挑选出来一些,按照学习的先后顺序,推荐给大家,特别是那些想不断提高自己技术水 ...
- Oracle 10g AND Oracle 11g手工建库案例--Oracle 10g
Oracle 10g AND Oracle 11g手工建库案例--Oracle 10g 系统环境: 操作系统: RedHat EL6 Oracle: Oracle 10g and Oracle 11 ...