【问题标题】:How to change uitableview delete button text如何更改uitableview删除按钮文本
【发布时间】:2011-11-15 17:40:47
【问题描述】:

您好,当用户在我的 tableview 中滑动 uitableviewcell 时,我正在尝试更改删除按钮中显示的文本。

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

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

我的问题是,我该如何使用这个方法.. 我不确定如何使用这个。

【问题讨论】:

    标签: iphone ios uitableview delegates


    【解决方案1】:

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

    例子:

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

    让你离开这样的事情:

    【讨论】:

    • 很好,但是为什么按钮的外观不再有动画了?添加后,删除按钮弹出而不是动画!编辑:我的错,一定是模拟故障。重新启动应用程序后再次正常。
    • @FaizanS。我也在调查这个。有没有办法只改变属性?类似于 ...self.tableView.deleteButton.name = @"Remove"; 而不是覆盖该方法?
    • 在撰写本文时还没有。在 iOS SDK 中,许多事情都是通过覆盖 UI 基类的现有方法来实现的。
    • 快捷方式:func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath:NSIndexPath) -> String{ return "Remove Me"; }
    • 在这个答案中没有理由添加<UITableViewDelegate>
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

      return @"Erase";
      

      阅读THIS

      同样在您的 .h 文件中,添加 UITableViewDelegate 以防您的视图控制器已经不是 UITableViewController。也就是说,它可以是:

      @interface SomeView : UIViewController <UITableViewDelegate>
      

      @interface SomeView : UITableViewController
      

      【讨论】:

        【解决方案4】:

        斯威夫特 4.2

        override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
                return "Erase"
            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-12-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-09-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多