当用户在我的桌面视图中滑动一个 uitableviewcell 时,我试图改变删除按钮中显示的文本。
我在另一个问题线程中看到过一个例子,说要使用这个 tableview 委托
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
我的问题是,我如何使用这个方法. . 我不知道如何使用这个。
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";
阅读 这个
Also in your .h file, add the UITableViewDelegate in case your view controller is not a UITableViewController already. That is it can be either:
@interface SomeView : UIViewController <UITableViewDelegate>
或者
@interface SomeView : UITableViewController
在管理 UITableView的控制器中,应该实现 UITableviewDelegate,并在 titleForDeleteConfirmationButtonForRowAtIndexPath方法中返回所需的方法标题。
UITableView
UITableviewDelegate
titleForDeleteConfirmationButtonForRowAtIndexPath
例如:
@interface CategoryAddViewController : UITableViewController @end @implementation CategoryAddViewController // ... -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { return @"Please don't delete me!"; } @end
就这样离开了你:
In Swift it is equal, just method signature is diferent!
func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? { return "Erase" }
Swift 4.2
override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? { return "Erase" }