【问题标题】:TableViewCell(SubView) trigger button show segue to new view controllerTableViewCell(SubView) 触发按钮显示 segue 到新的视图控制器
【发布时间】:2017-03-15 13:22:27
【问题描述】:

我在 tableviewcell 中有一个 BUTTON,它具有 Action Segue 显示到下一个视图控制器。我在 tableviewcell 内也有一个 UIView

I wish to use the UIView(Green) Tap gesture action to trigger the button show segue action

有什么指南可以参考吗?感谢阅读。

【问题讨论】:

  • 为什么要让视图触发按钮操作?或者如果我错了,你想在点击视图并将背景颜色更改为绿色后继续。??
  • @TusharSharma 感谢您的评论。我有一个默认按钮设置,将被单击以查看下一个视图控制器。因此,我创建了一个新的 UIView 并希望点击手势来执行默认按钮操作。

标签: ios swift uiview


【解决方案1】:

你不需要触发button action来调用segue,你可以使用下面的代码在tap gesture action中以编程方式调用它。

[self performSegueWithIdentifier:@"yourSegueId" sender:nil];

【讨论】:

    【解决方案2】:

    在您的点击手势动作中,添加以下内容:

    self.performSegue(withIdentifier:"YourSegueIdentifierInStoryboard", sender: yourButton)
    

    【讨论】:

      【解决方案3】:

      我会这样做: 为包含回调函数的单元声明一个协议

      func cellGreenButtonTouched(button:UIButton)
      

      然后在 tableViewController 中实现这个协议。 从那里,您可以调用: pushViewController() 或 performSegueWithIdentifier()

      为了触摸绿色按钮来触发调用,您必须将按钮(CTRL+从按钮拖动)绑定到单元格的委托本地函数

      func greenButtonTouchedUpInside(...) {
        delegate?.cellGreenButtonTouched(button:button)
      }
      

      这应该工作得很好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-25
        • 2017-05-13
        • 1970-01-01
        • 1970-01-01
        • 2020-02-05
        • 1970-01-01
        相关资源
        最近更新 更多