我在 TableView 单元格中有一个带有 TapGesture 的标签,如果按下该标签,该标签应该关闭嵌入在导航 Controller 中的 View Controller 。
通常我会这样做:
_ = navigationController?.popViewController(animated: true)
或者
self.dismiss(动画:true)
但这在 TableView 单元格类中不起作用。
如果有人能帮助我,那就太好了!
最佳答案
为了让它工作,你应该将该义务传递给管理你的 tableView 的 viewController 。因此,在你的 tableViewCell 类上面声明一个带有函数的协议(protocol),委托(delegate)(在本例中是持有你的 tableView 的 ViewController)在调用时应该实现该函数。因此,当在 ViewController 内调用委托(delegate)时,如果 ViewController 是模态呈现的,则关闭 ViewController;如果是推送的,则弹出它,因此您上面提到的方法之一应该可以工作。如果您不知道自定义协议(protocol)如何工作,请尝试阅读这篇文章 https://medium.com/@aapierce0/swift-using-protocols-to-add-custom-behavior-to-a-uitableviewcell-2c1f09610aa1
关于swift - 在 TableViewCell 中按下标签时关闭 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52005751/