How to change iPhone UITableView delete button title while editing it

前端 未结 4 1498
礼貌的吻别
礼貌的吻别 2020-12-09 15:02

I need to change the title of the default delete button that appears when I attempt to delete a row from a UITableView after setting editing to YES

相关标签:
4条回答
  • 2020-12-09 15:44

    Swift 3

    With a small difference _

    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
        return "Erase"
    }
    
    0 讨论(0)
  • 2020-12-09 15:45

    Swift

    Add this method to your UITableView delegate (probably your view controller).

    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
        return "Erase"
    }
    

    This makes the button say "Erase" but you can use any string you want.

    My fuller answer is here.

    0 讨论(0)
  • 2020-12-09 15:51

    You can change it in UITableView delegate method

    - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
    
    0 讨论(0)
  • 2020-12-09 15:59

    For those who already have implemented method 'titleForDeleteConfirmationButtonForRowAtIndexPath' and still see same 'Delete' text.

    Try to type in method from scratch with autocompletion, because I copied someone's and it has a little bit different older notation and didn't get called!

    0 讨论(0)
提交回复
热议问题