简体   繁体   English

TableViewCell(SubView)触发按钮向新视图控制器显示序列

[英]TableViewCell(SubView) trigger button show segue to new view controller

i have one BUTTON in tableviewcell which has Action Segue show to next view controller. 我在tableviewcell中有一个按钮 ,其中Action Segue显示给下一个视图控制器。 And i have a UIView inside the tableviewcell as well. 我在tableviewcell中也有一个UIView

I wish to use the UIView(Green) Tap gesture action to trigger the button show segue action 我希望使用UIView(Green)Tap手势动作来触发按钮show segue动作

Is there any guide for me to refer? 有什么指南可供我参考吗? Thanks for reading. 谢谢阅读。

You don't need to trigger button action to call segue, you can call it programmatically in tap gesture action using the below code. 您无需触发button action即可调用segue,您可以使用以下代码以tap gesture action以编程方式调用它。

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

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

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

The way I would do it: Declare a protocol for the cell including a callback function 我的操作方式:声明包含回调函数的单元格协议

func cellGreenButtonTouched(button:UIButton)

then implement this protocol in the tableViewController. 然后在tableViewController中实现此协议。 From there, you can just call: pushViewController() or performSegueWithIdentifier() 从那里,您可以仅调用:pushViewController()或performSegueWithIdentifier()

In order to have the touch on the green button to trigger the call, you'll have to bind the button (CTRL+drag from the button) to the cell's delegate local function 为了触摸绿色按钮以触发呼叫,您必须将按钮(从按钮上按CTRL +拖动)绑定到单元格的委托本地功能

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

This should work perfectly well. 这应该工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM