之前一直想了解這個(gè)功能是怎么實(shí)現(xiàn)的趴腋,但是沒有需求就沒有動力赃梧,今天終于遇到了這個(gè)問題,也仔細(xì)看了看
1.iOS3.0及以上
在tableViewDelegate 實(shí)現(xiàn)以下方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// 刪除數(shù)據(jù)源對應(yīng)模型
[self.arrays removeObjectAtIndex:indexPath.row];
// 從tableView中刪除
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationTop];
}
缺點(diǎn):只能使用系統(tǒng)原生delete妓笙,文字宰衙,圖片皆不可修改。
2.iOS8.0及以上
在tableViewDelegate 實(shí)現(xiàn)以下方法
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"你想要修改的文字" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點(diǎn)擊了闯估。灼舍。。");
// 收回左滑出現(xiàn)的按鈕(退出編輯模式)
tableView.editing = NO;
}];
UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
//[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
NSLog(@"點(diǎn)擊了涨薪。骑素。。");
}];
return @[action0,action1];
}
如圖
3.如果以上還不能滿足我們的需求只能使用別人家的了(東西都是人家的好8斩帷)