美文网首页
tableViewCell 侧滑(功能botton)

tableViewCell 侧滑(功能botton)

作者: CoderChou | 来源:发表于2016-06-21 15:03 被阅读1007次

之前一直想了解这个功能是怎么实现的,但是没有需求就没有动力,今天终于遇到了这个问题,也仔细看了看
1.iOS3.0及以上
在tableViewDelegate 实现以下方法


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
        // 删除数据源对应模型
        [self.arrays removeObjectAtIndex:indexPath.row];
        // 从tableView中删除
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationTop];
}

缺点:只能使用系统原生delete,文字,图片皆不可修改。

2.iOS8.0及以上
在tableViewDelegate 实现以下方法

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"你想要修改的文字" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        NSLog(@"点击了。。。");
        
        // 收回左滑出现的按钮(退出编辑模式)
        tableView.editing = NO;
    }];
    UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        //[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        NSLog(@"点击了。。。");
    }];
    
    return @[action0,action1];
    
    
}
如图

3.如果以上还不能满足我们的需求只能使用别人家的了(东西都是人家的好!)

MGSwipeTableCell

相关文章

  • tableViewCell 侧滑(功能botton)

    之前一直想了解这个功能是怎么实现的,但是没有需求就没有动力,今天终于遇到了这个问题,也仔细看了看1.iOS3.0及...

  • ios tableviewcell侧滑功能

    先看效果图: 不啰嗦,直接上代码:(iOS8.0还是iOS9.0后必须写的一个代理方法,不然无法实现左滑效果) 当...

  • 自定义UITableViewCell侧滑

    LBSideslipCell 自定义tableViewCell侧滑按钮 自定义的UITableViewCell侧滑...

  • tableviewCell侧滑

    不幸地是这个API只在iOS8才有,这样iOS8以下就没办法使用到这种效果。这种情况下我们不得不使用第三方库或者自...

  • UITableViewCell多按钮侧滑

    一.关于tableViewCell的侧滑,系统默认只有一个按钮:(删除或插入),代码如下: 二.关于tableVi...

  • 侧滑返回功能

    既要自定义返回按钮,也要侧滑返回功能!! 当我们用自定义的按钮覆盖了系统的返回按钮时,侧滑返回功能会失效。 为什么...

  • 18

    文章的侧滑功能 前端代码

  • Android界面双击退出实现

    非常常见的功能 这里额外实现了有侧滑菜单的版本 包含侧滑菜单版本

  • 侧滑返回冲突问题

    1如下图参数配置 需求:红色区域可侧滑返回 绿色区域不可以, 绿色区域 横向是tableviewcell里套的co...

  • 简单实现侧滑功能

    话不多说,先来个效果图: 侧滑这个功能大家应该很熟悉吧,只要你用QQ,那么肯定就会接触到侧滑了,我今天主要是讲实现...

网友评论

      本文标题:tableViewCell 侧滑(功能botton)

      本文链接:https://www.haomeiwen.com/subject/mgdgdttx.html