Rename the button is pretty simple, it’s just about change that string on a specialized method that is in charge of do that work.
On ItemsViewController add:
override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
return "Remove"
}
Hi, thanks for your solution, I’ve got a qq for you: how did you know where to find this? I’ve perused the docs a bit, but don’t seem to have the intuition on where to start my search when these questions come up.
Also, any ideas (other than the fact that it’s mentioned in the documentation) why the return type need to be an optional String?
Hello!
Well, i think the optional string it’s because documentation recommends a localized string to use as the title of the delete-confirmation button, in that way you can evaluate with a if let conditional if there is a valid string.
I’m a android Developer and all the questions that comes up every days, i first look up on internet, and then I start with that knowledge on the documentation. It’s my faster technique when nobody can help me and it’s very efficient too.
Hi, I’m not the one who answered the question, but I think I can help you regarding your question about how to find the relevant methods to override and implement.
I use an offline documentation viewer, for the Mac, it’s Dash, and for Windows, it’s Zeal.
They both allow you to download documentation offline and have really good search capabilities.
While solving this problem, it probably took me mere minutes, and here’s how it went.
- I searched Dash for UITableViewDelegate
- Dash showed me a list of all methods in that class
- Methods were grouped by headings
- One of the headings caught my eye, it was Editing Table Rows
- I clicked it and found five methods in it
- One of those methods was:
func tableView(UITableView, titleForDeleteConfirmationButtonForRowAt: IndexPath) → String?
- I clicked on it, and the read the description for that method, and thus solved the problem.
I’ve found that using an offline documentation viewer has probably been the most productive thing for writing code.
I hope this helped you somewhat.
Wow, thanks so much for this! I have realized that one of my biggest questions when I come across some new code is “How did you know to do that?” So this will be a great help, thanks!!!
I came up with a different approach, which also allows to change color and action:
override func tableView(_ tableView: UITableView,
editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
// delAction is a new delete device coming up, when - sgn is pressed for deleting rows
let delAction: UITableViewRowAction = UITableViewRowAction(style: .normal, title: "Remove") {
(deleteAction, indexPath) in
// Calling the tableView function, which does the delete action
self.tableView(self.tableView, commit: .delete, forRowAt: indexPath)
}
// Change background color
delAction.backgroundColor = UIColor.orange
return [delAction]
}