【问题标题】:Need to double tap on cell to present modally VC需要双击单元格以呈现模态 VC
【发布时间】:2018-06-02 18:01:47
【问题描述】:

我正在生成表格单元格。

cell2 = settingsTableView.dequeueReusableCell(withIdentifier: "ModuleCell", for: indexPath) as! ModuleCell

看起来不错,单元格有tag = 2000

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath),我正在检查标签结尾if tag == 2000 我想呈现模态视图。我就是这样做的

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let modalView = storyboard.instantiateViewController(withIdentifier: "ModalView")
present(modalView, animated: true, completion: nil)

然后在 modalView 我有一个按钮应该关闭 modalView,这是按预期发生的。

@IBAction func saveAndClosePopup(_ sender: UIButton) {
        UserDefaults.standard.removeObject(forKey: "ActiveCantachoOptions")
        UserDefaults.standard.set(Modules.activeCantachoOptions, forKey: "ActiveCantachoOptions")

        self.dismiss(animated: true, completion: nil)
    }

但是,当我想立即再次呈现modalView时,有时还可以,但有时我需要在单元格上点击两次,这应该显示modalView。第一次击中后,如果我在 1 秒或 30 秒内再次击中单元格,则没有区别。 modalView 将出现在第二个之后。原因是什么?

【问题讨论】:

  • 既然你重写了tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath),你会调用super方法吗?
  • 你有没有向视图控制器添加任何点击/长按手势识别器?我之前曾多次看到这些干扰细胞选择
  • @Crazyrems 好吧,我不认为如果在 didSelectRowAt 调用中 super 是必要的,但我可能错了。
  • @Scriptable 没有添加任何点击手势识别器。

标签: ios iphone swift modalviewcontroller


【解决方案1】:

试试这个

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{


  let storyboard = UIStoryboard(name: "Main", bundle: nil)
  let modalView = storyboard.instantiateViewController(withIdentifier: "ModalView")

    self.present(modalView, animated: true) {        

       tableView.deselectRow(at: indexPath, animated: false)

 }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 2016-01-27
    相关资源
    最近更新 更多