xcode UITableView 编辑模式显示自定义按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4716324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UITableView Edit Mode Show Custom Buttons
提问by Cheryl
I know that people hate vague questions here so I just need a yes or no answer. I have a tableView and I want people to be able to edit the contents of the table.
我知道人们讨厌这里含糊不清的问题,所以我只需要一个是或否的答案。我有一个 tableView,我希望人们能够编辑表格的内容。
I like the setEditing method but I don't want the button to say Delete - I would prefer Remove and there are times where I want to display more than one button and hide the delete button. I just need to know if this is possible.
我喜欢 setEditing 方法,但我不希望按钮显示删除 - 我更喜欢删除,有时我想显示多个按钮并隐藏删除按钮。我只需要知道这是否可能。
I am ready to give up on using the standard edit and delete buttons and just make my own but before I did I wanted to know what was possible.
我已经准备好放弃使用标准的编辑和删除按钮,只做我自己的,但在我这样做之前我想知道什么是可能的。
Thanks very much Cheryl
非常感谢谢丽尔
回答by Kenny Wyland
Just implement this method on your UITableViewDelegate:
只需在您的 UITableViewDelegate 上实现此方法:
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
Then you can set the title for that delete button and make it say "Remove" instead.
然后,您可以为该删除按钮设置标题,并改为显示“删除”。
回答by ughoavgfhw
As Kenny pointed out, you can use the tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: method to change the title of the delete button. If you want to use a different button altogether, use UITableViewCell's editingAccessoryView property to change the view shown in editing mode.
正如 Kenny 指出的,您可以使用 tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: 方法来更改删除按钮的标题。如果您想完全使用不同的按钮,请使用 UITableViewCell 的editingAccessoryView 属性来更改在编辑模式下显示的视图。