ios 如何更改uitableview删除按钮文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7394988/
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
How to change uitableview delete button text
提问by C.Johns
Hi there I am trying to change the text that is showing in the delete button when a user swipes a uitableviewcell inside my tableview.
嗨,当用户在我的 tableview 中滑动 uitableviewcell 时,我正在尝试更改显示在删除按钮中的文本。
I have seen an example in another question thread that says to use this tableview delegate
我在另一个问题线程中看到了一个例子,它说使用这个 tableview 委托
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
My question is, how do I use this method.. I am not sure how to use this.
我的问题是,我如何使用这种方法..我不确定如何使用它。
回答by Faizan S.
In your controller managing the UITableView
you should implement the UITableviewDelegate
and return the title you want for your method inside the titleForDeleteConfirmationButtonForRowAtIndexPath
method.
在您的控制器管理中,UITableView
您应该实现UITableviewDelegate
并在方法内为您的方法返回您想要的标题titleForDeleteConfirmationButtonForRowAtIndexPath
。
Example:
例子:
@interface CategoryAddViewController : UITableViewController
@end
@implementation CategoryAddViewController
// ...
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"Please don't delete me!";
}
@end
Leaving you off with something like that:
让你离开这样的事情:
回答by Weles
In Swift it is equal, just method signature is diferent!
在 Swift 中它是平等的,只是方法签名不同!
func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
return "Erase"
}
回答by Bourne
Just return the string that you want to display instead of delete. Say you wish to show "Erase" for all rows, the above function should contain:
只需返回要显示的字符串而不是删除。假设您希望对所有行显示“擦除”,上述函数应包含:
return @"Erase";
Read THIS
阅读本
Also in your .h file, add the UITableViewDelegate in case your view controller is not a UITableViewController already. That is it can be either:
同样在您的 .h 文件中,添加 UITableViewDelegate,以防您的视图控制器已经不是 UITableViewController。也就是说,它可以是:
@interface SomeView : UIViewController <UITableViewDelegate>
OR
或者
@interface SomeView : UITableViewController