为了账号安全,请及时绑定邮箱和手机立即绑定

滑动以删除并单击“更多”按钮(例如,在iOS 7上的Mail应用程序中)

滑动以删除并单击“更多”按钮(例如,在iOS 7上的Mail应用程序中)

不负相思意 2019-12-07 14:51:10
用户在表格视图中滑动单元格时如何创建“更多”按钮(如ios 7中的邮件应用程序)我一直在这里和Cocoa Touch论坛上都在寻找这些信息,但是我似乎找不到答案,我希望有一个比我自己更聪明的人给我解决方案。我希望当用户滑动表格视图单元格时,显示多个编辑按钮(他默认是删除按钮)。在iOS 7的邮件应用中,您可以滑动以删除,但是会出现一个“更多”按钮。
查看完整描述

3 回答

?
慕神8447489

TA贡献1780条经验 获得超1个赞

我只是在Objective-C中添加以下内容,以使初学者(以及我们中那些拒绝学习Swift语法的人)更加清楚:


确保声明uitableviewdelegate并具有以下方法:


 -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

 UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)

    {

        NSLog(@"Action to perform with Button 1");

    }];

    button.backgroundColor = [UIColor greenColor]; //arbitrary color

    UITableViewRowAction *button2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 2" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)

                                    {

                                        NSLog(@"Action to perform with Button2!");

                                    }];

    button2.backgroundColor = [UIColor blueColor]; //arbitrary color


    return @[button, button2]; //array with all the buttons you want. 1,2,3, etc...

}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

// you need to implement this method too or nothing will work:


}

 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

    {

        return YES; //tableview must be editable or nothing will work...

    }


查看完整回答
反对 回复 2019-12-07
?
智慧大石

TA贡献1946条经验 获得超3个赞

现在可以使用以下公共API来完成此操作:


func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {


    let moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "More", handler:{action, indexpath in

        print("MORE•ACTION");

    });

    moreRowAction.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);


    let deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Delete", handler:{action, indexpath in

        print("DELETE•ACTION");

    });


    return [deleteRowAction, moreRowAction];

}


查看完整回答
反对 回复 2019-12-07
  • 3 回答
  • 0 关注
  • 630 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信