你好,我想要更改用户滑动uitableviewcell时在删除按钮上显示的文本。
我在另一个问题的主题中看到了一个示例,建议使用此tableView委托方法:
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
我有一个问题,我应该如何使用这个方法?我不确定如何使用它。你好,我想要更改用户滑动uitableviewcell时在删除按钮上显示的文本。
我在另一个问题的主题中看到了一个示例,建议使用此tableView委托方法:
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
我有一个问题,我应该如何使用这个方法?我不确定如何使用它。在管理UITableView
的控制器中,您应该实现UITableviewDelegate
并在titleForDeleteConfirmationButtonForRowAtIndexPath
方法中返回您想要的标题。
示例:
@interface CategoryAddViewController : UITableViewController
@end
@implementation CategoryAddViewController
// ...
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"Please don't delete me!";
}
@end
在Swift中它是相等的,只是方法签名不同!
func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
return "Erase"
}
只需返回您想要显示的字符串而不是删除。假设您希望为所有行显示“擦除”,则上述函数应包含:
return @"Erase";
阅读此文
而且,在您的.h文件中,添加UITableViewDelegate,以防您的视图控制器尚未是UITableViewController。这可以是:
@interface SomeView : UIViewController <UITableViewDelegate>
或者
@interface SomeView : UITableViewController
Swift 4.2
override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
return "Erase"
}
func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath:NSIndexPath) -> String{ return "删除"; }
- dy_<UITableViewDelegate>
。 - rmaddy