如何更改uitableview删除按钮文本

C.J*_*hns 76 iphone delegates uitableview ios

嗨,我正在尝试更改用户在我的tableview中刷一个uitableviewcell时在删除按钮中显示的文本.

我在另一个问题线程中看到了一个例子,说明要使用这个tableview委托

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

我的问题是,我如何使用这种方法..我不知道如何使用它.

Fai*_* S. 194

在你的控制器中管理UITableView你应该实现UITableviewDelegate并在方法中返回你想要的方法标题titleForDeleteConfirmationButtonForRowAtIndexPath.

例:

@interface CategoryAddViewController : UITableViewController
@end

@implementation CategoryAddViewController
// ...
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"Please don't delete me!";
}

@end
Run Code Online (Sandbox Code Playgroud)

让你离开这样的事情:

在此输入图像描述

  • 快捷方式:`func tableView(tableView:UITableView,titleForDeleteConfirmationButtonForRowAtIndexPath indexPath:NSIndexPath) - > String {return"Remove Me"; }` (2认同)

Wel*_*les 30

在Swift中它是平等的,只是方法签名是不同的!

func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
  return "Erase"
}
Run Code Online (Sandbox Code Playgroud)