如何更改 Swift 表格视图单元格中的默认删除按钮? [英] How to change the default delete button in a table view cell in Swift?

查看:30
本文介绍了如何更改 Swift 表格视图单元格中的默认删除按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Swift 中实现这段代码.我从这些问题中在 Objective-C 中得到了以下代码:

I want to implement this code in Swift. I got the following code for it in Objective-C from these questions:

更改颜色滑动行或点击编辑按钮时 UITableViewCell 中默认的红色删除按钮

自定义 UITableView 中的删除按钮

- (void)willTransitionToState:(UITableViewCellStateMask)state{
[super willTransitionToState:state];
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
    for (UIView *subview in self.subviews) {
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
            UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
            [deleteBtn setImage:[UIImage imageNamed:@"delete.png"]];
            [[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
            [deleteBtn release];
        }
    }
}
}

我不知道如何在 Swift 中实现这个方法.有人可以帮我吗?

I don't know how to implement this method in Swift. Could anyone help me?

我使用的是 Xcode 7.3 Beta.

I am using Xcode 7.3 Beta.

推荐答案

swift tableview 委托有新方法.试试这个可能会解决你的问题.

swift tableview delegate have new method. Try this may be it will resolve your problem.

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?{

    let ackAction = UITableViewRowAction(style: .default, title: "Himanshu", handler: myFunction)
        ackAction.backgroundColor = UIColor.orange

    return [ackAction]
}

现在您甚至可以修改删除功能

Now you can even modify your delete functionality

这篇关于如何更改 Swift 表格视图单元格中的默认删除按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆