【问题标题】:create a popover segue clicking a view inside a tableview cell单击 tableview 单元格内的视图创建弹出框 segue
【发布时间】:2016-03-23 10:51:54
【问题描述】:

所以我试图创建一个弹出框,在单击 tableview 单元格内的视图时出现。这是我到目前为止所尝试的。 这就是我的 customcell 中的内容:

class Cell: UITableViewCell {

@IBOutlet weak var openingHoursView: CustomView!

override func awakeFromNib() {
    super.awakeFromNib()
    let tap = UITapGestureRecognizer(target: self, action: Selector("openingHoursTap:"))
    openingHoursView.addGestureRecognizer(tap)
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
}
}

这就是我在视图控制器中的内容:

    else if segue.identifier == "openingHours" {
        var vc = segue.destinationViewController
        var controller = vc.popoverPresentationController
        if controller != nil {
            controller?.delegate = self
        }
    }

@IBAction func openingHoursTap(sender: UITapGestureRecognizer) {
    performSegueWithIdentifier("openingHours", sender: self)
}


func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return .None
}

标识符正确。锚点位于 segue 的 tableview 上。我以前从未真正创建过可点击的视图,但只是用一个按钮做了同样的事情,而且效果很好。没有错误,应用只是在点击视图时崩溃。

我猜这可能与我没有将其添加到单个单元格的 cellForRowAtIndexPath 中有关。如果我不能 addTarget 怎么办?

【问题讨论】:

  • 您在表格单元格中调用openingHoursTap:,但您对openingHoursTap: 的实际实现在您的视图控制器中,对吗?
  • 正确,尝试在我的 tableview 中实现它

标签: ios swift uitableview uistoryboardsegue


【解决方案1】:

您在表格视图单元格中调用openingHoursTap:,但您的实际实现在您的视图控制器中。这就是它崩溃的原因。所以正确的方法是在视图控制器的tableView: cellForRowAtIndexpath: 中添加点击手势识别器。

例子:

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell")
let tap = UITapGestureRecognizer(target: self, action:Selector("openingHoursTap:"))
cell.openingHoursView.addGestureRecognizer(tap)
}

【讨论】:

  • 啊,是的,有道理,不知道如何将它添加到 cellForRowAtIndexpath。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-01
  • 1970-01-01
相关资源
最近更新 更多