您的位置:首页 > 产品设计 > UI/UE

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: