0

I am generating table cell.

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

It looks fine, the cell has tag = 2000.

In override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath), I am checking the tag end if tag == 2000 I want to present modal view. I am doing that in this way

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

Then in modalView I have a button which should dismiss modalView, what's happening as expected.

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

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

However, when I want to immediately present modalView again, sometimes it's okay, but sometimes I need to hit two times on the cell, which should show modalView. After the first hit, there is no difference if I hit the cell again in 1 second or in 30 seconds. The modalView will appear after the second one. What is the cause?

Micgal
  • 133
  • 1
  • 1
  • 11
  • 1
    it will help you https://stackoverflow.com/questions/22585416/slow-performance-for-presentviewcontroller-depends-on-complexity-of-presenting – Dharma Dec 20 '17 at 08:26
  • Since you're overriding `tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)`, do you call the super method? – Crazyrems Dec 20 '17 at 08:34
  • have you added any tap/long tap gesture recogisers to the view controller at all? I have seen these interfere with cell selection a few times before – Scriptable Dec 20 '17 at 08:38
  • @Crazyrems well, I don't think so if in didSelectRowAt call the super is necessary, but I may be wrong. – Micgal Dec 20 '17 at 08:42
  • @Scriptable there is no any tap gesture recogniser added. – Micgal Dec 20 '17 at 08:43
  • @DSDharma I think there is much more better now, when followed. deselectRow made it works. I will test more – Micgal Dec 20 '17 at 08:44
  • @Micgal you don't need to if the method is a call to a delegate, but here you're subclassing `UITableViewController`, wich implements lots of things under the hood _(like autosizing cells)_. – Crazyrems Dec 20 '17 at 08:45

1 Answers1

0

Try this

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)

 }
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87