开发者

How to change iPhone UITableView delete button title while editing it

开发者 https://www.devze.com 2022-12-09 07:52 出处:网络
I need to change the title of the default delete button that 开发者_JS百科appears when I attempt to delete a row from a UITableView after setting editing to YES.You can change it in UITableView delega

I need to change the title of the default delete button that 开发者_JS百科appears when I attempt to delete a row from a UITableView after setting editing to YES.


You can change it in UITableView delegate method

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath


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.

How to change iPhone UITableView delete button title while editing it

My fuller answer is here.


Swift 3

With a small difference _

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


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

精彩评论

暂无评论...
验证码 换一张
取 消