【问题标题】:How to access the view of a UITableViewRowAction iOS 8如何访问 UITableViewRowAction iOS 8 的视图
【发布时间】:2014-10-02 12:29:12
【问题描述】:

我已经使用UITableViewRowAction 为表格视图的行实现了一些编辑操作。其中之一是删除操作,我想展示一个包含操作表的弹出框以确认删除操作。因此,我需要对删除按钮视图的引用以将其传递给UIPopoverPresentationController

有什么方法可以访问UITableViewRowAction对象的视图?

为了更清楚一点,我试图访问的视图是红色的删除按钮,标记为绿色:

【问题讨论】:

  • Swift 还是 Objective C?
  • @derdida 更喜欢 Objective C,但两者都能理解
  • 你刷过的单元格的 indexPath 被传递给处理程序。这还不够吗?
  • @rdelmar 我想要包含“删除”按钮的矩形红色视图,所以我可以将它传递给弹出框控制器。
  • @derdida:你有没有找到解决方案?我也想这样做。谢谢

标签: ios ios8


【解决方案1】:

抱歉,我不知道它的 Objective-C 版本,但我现在在 Swift 中的一个项目中使用它,它应该可以工作。虽然它只是 iOS 8,但我不确定在此之前有没有办法做到这一点。

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {

    var deleteButton: UITableViewRowAction = UITableViewRowAction(style: .Default, title: "       ", handler: { (action, indexPath) in

            // put whatever you need to call here. below is the default code, which will delete the cell as usual. 
            self.tableView.dataSource?.tableView?(
                self.tableView,
                commitEditingStyle: .Delete,
                forRowAtIndexPath: indexPath

            )

            return
        })
    }
    return [deleteButton]
}

您的另一个选择是使用 tableview 功能:

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)

您可以在哪里创建一个弹出窗口并让他们确认。实际上,这可能会更好,我相信这正是该功能的用途。

编辑:忘记了第一段代码中的返回 [deleteButton]。

【讨论】:

    【解决方案2】:

    UIView *view = sender.superview; //单元格内容视图

    CustomCell *cell; // (you can custom tableviewcell name if created)
    if(SYSTEM_VERSION_GREATER_THAN(@"8.0"))
    {
        cell = (CustomCell *)view.superview;
    }
    else{
        cell = (CustomCell *)[[[sender superview] superview]superview];
    
    }
    
    And Access it by :-
    cell.view
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-08
      • 2011-06-16
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      • 2016-01-11
      • 1970-01-01
      相关资源
      最近更新 更多