首页 文章

如何更改uitableview删除按钮文本

提问于
浏览
74

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

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

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

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

3 回答

  • 4

    在管理 UITableView 的控制器中,您应该实现 UITableviewDelegate 并在 titleForDeleteConfirmationButtonForRowAtIndexPath 方法中为您的方法返回所需的 Headers .

    例:

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

    让你离开这样的事情:

    enter image description here

  • 26

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

    func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
      return "Erase"
    }
    
  • 192

    只需返回要显示的字符串而不是删除 . 假设您希望为所有行显示“擦除”,则上述功能应包含:

    return @"Erase";
    

    阅读THIS

    同样在.h文件中,添加UITableViewDelegate以防视图控制器不是UITableViewController . 那就是它可以是:

    @interface SomeView : UIViewController <UITableViewDelegate>
    

    要么

    @interface SomeView : UITableViewController
    

相关问题