【问题标题】:How to use UITapGestureRecognizer on static UITableViewCell?如何在静态 UITableViewCell 上使用 UITapGestureRecognizer?
【发布时间】:2015-06-03 16:28:04
【问题描述】:

如何在静态UITableViewCell 上使用UITapGestureRecognizer?到目前为止,我刚刚为静态 UITableViewCell 创建了一个 IBOutlet

@IBOutlet weak var settingCell: UITableViewCell!

我想要的是当用户点击这个UITableViewCell 时触发这个IBOutlet

@IBAction func share(sender: AnyObject) {
    let vc = UIActivityViewController(activityItems: [NSURL(string:"https://www.apple.com/my/itunes/")!], applicationActivities: nil)
    /* If you want to exclude certain types from sharing
    options you could add them to the excludedActivityTypes */
    vc.excludedActivityTypes = [UIActivityTypePostToTwitter]
    self.presentViewController(vc, animated: true, completion: nil)
}

我该怎么做?

【问题讨论】:

    标签: ios uitableview swift iboutlet


    【解决方案1】:

    如果我明白你想要什么,你不需要使用 UITapGestureRecognizer,你可以简单地设置 tableView 及其协议(你可能已经制作了),并使用这个函数:

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
         //your action comes in here
    }
    

    【讨论】:

      【解决方案2】:

      如果您需要tripleTap/doubleTap。您应该在 customTVC 文件中添加手势识别器。

      您可能希望从 tableViewController 传递 completionHandler 或在 customTVC 级别处理它。

      请注意,您可能需要禁用表格视图行选择

      将手势识别器添加到 TVC 类似于将其添加到任何 uiview。但请注意 awakeFromNib 并不总是被调用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-13
        • 1970-01-01
        相关资源
        最近更新 更多