UITableView的删除,移动及修改删除按钮上的文字
2012-08-29 21:15
441 查看
其实修改UITableView进行删除操作的时候右边出现的删除按钮上的文字很简单:
重写delegate方法:-(NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexpath;
如果需要出现UITableView上滑动cell时出现删除按钮的话,需要进行一下操作:
首先设置你的UITableViewCell的EditingStyle是UITableViewCellEditingStyleDelete,这个时候有多种方法,
一是创建cell的时候直接设置,
二是在tableview的delegate中设置,delegate方法如下:
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath;
针对响应的indexpath返回UITableViewCellEditingStyleDelete。
三是你不要尝试自己设置cell的editingStyle属性也不要重载方法二中的方法,这样默认状态下cell的editingStyle值即为UITableViewCellEditingStyleDelete。
其次是最关键的,你一定要重载uitableview的这个delegate方法,否则是无法滑动弹出删除按钮的,
-(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath;
原因想想应该也简单,如果没有这个函数你根本就无法找到触发点击那个弹出删除按钮后的方法。
如果会对按钮的出现和消失的时刻感兴趣,那么此刻要实现代理的方法(下面的2 3):
(1)- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
(2)- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath*)indexPath
(3)- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath*)indexPath
在删除按钮显示出来之前会调用(2)方法,给我们处理问题的时间。
其实上述方法的调用顺序就是 (2)--->(1)----->(3)
而UITableView编辑时如何能移动UITableViewCell也简单,即实现UITableView的moveRow这个方法:
-(void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)indexPath toIIndexPath:(NSIndexPath*)indexPath;
这样当你设置UITableView的editing为YES的时候就会出现移动cell的那种按钮了。
=========================================
附带内容:
关于group的UITableView的section跳转时,实现下面方法可以重新定位点击哪个section来跳转到哪个section
-(void)tableView:(UITableView*)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger*)index;
重写delegate方法:-(NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexpath;
如果需要出现UITableView上滑动cell时出现删除按钮的话,需要进行一下操作:
首先设置你的UITableViewCell的EditingStyle是UITableViewCellEditingStyleDelete,这个时候有多种方法,
一是创建cell的时候直接设置,
二是在tableview的delegate中设置,delegate方法如下:
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath;
针对响应的indexpath返回UITableViewCellEditingStyleDelete。
三是你不要尝试自己设置cell的editingStyle属性也不要重载方法二中的方法,这样默认状态下cell的editingStyle值即为UITableViewCellEditingStyleDelete。
其次是最关键的,你一定要重载uitableview的这个delegate方法,否则是无法滑动弹出删除按钮的,
-(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath;
原因想想应该也简单,如果没有这个函数你根本就无法找到触发点击那个弹出删除按钮后的方法。
如果会对按钮的出现和消失的时刻感兴趣,那么此刻要实现代理的方法(下面的2 3):
(1)- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
(2)- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath*)indexPath
(3)- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath*)indexPath
在删除按钮显示出来之前会调用(2)方法,给我们处理问题的时间。
其实上述方法的调用顺序就是 (2)--->(1)----->(3)
而UITableView编辑时如何能移动UITableViewCell也简单,即实现UITableView的moveRow这个方法:
-(void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)indexPath toIIndexPath:(NSIndexPath*)indexPath;
这样当你设置UITableView的editing为YES的时候就会出现移动cell的那种按钮了。
=========================================
附带内容:
关于group的UITableView的section跳转时,实现下面方法可以重新定位点击哪个section来跳转到哪个section
-(void)tableView:(UITableView*)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger*)index;
相关文章推荐
- ITableView的删除,移动及修改删除按钮上的文字,来自,dick_china
- UITableView实现删除移动编辑的样式(转)
- UITableView 左右滑动时,出现删除按钮的动画。
- UITableView删除添加,移动,分区,索引,自定义UITableViewCell
- iOS开发:UITableView编辑——cell的删除和移动
- UITableView删除按钮iOS10适配
- 修改UITableView中Delete操作的默认按钮
- [11]UITableView编辑 删除 添加 移动 单例 及其去掉TableView没内容的Cell
- (三)UITabBar and UINavigationController基础教程之UITableView的插入删除移动
- 怎么用代码弹回 UITableView 中左滑出来的删除按钮
- iOS开发给UITableView的单元格做一个类似于QQ和微信的侧滑露出删除按钮的思路
- 【精】表格(UITableView)总结(4):编辑(增加、删除、移动)
- 让提示小View随着按钮或者label的移动而移动,长短随着文字的长短而变化
- UItableView中编辑,删除,移动学习笔记
- IOS_修改TableView的删除按钮的文本
- UItableView的编辑--删除移动cell
- UITableView之(二):删除、移动
- UITableView 左右滑动时,出现删除按钮的动画(可自定义)。
- UITableView的移动、删除操作
- UITableView (4): 在TableView中移动cell和Section 从TableView中删除cell和section 添加系统默认刷新控件