Kautham Murugan Kautham Murugan - 5 months ago 92
iOS Question

How to change the default delete button in a table view cell in Swift?

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

Change the color of default red color delete button in UITableViewCell when swiping rows or click on edit button

Customize the delete button in 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];

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

I am using Xcode 7.3 Beta.


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

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

    let ackAction:UITableViewRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Himanshu", handler: myFunction)
        ackAction.backgroundColor = UIColor.orangeColor()

    return [moreAction]

Now you can even modify your delete functionality