Search code examples
iosswiftuitableviewuipopovercontrollerdidselectrowatindexpath

Swift Presenting popover from UITableView runs very slow


I am not really sure why this runs slow. Sometimes I can tap the row and it opens the popup instantly. Sometimes I can tap the row and it takes 2-3 seconds to load. Almost seems like maybe the code is confused on getting the cell.

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let selectedItem = self.filteredTransactions[indexPath.row]
    if let cell = tableView.cellForRowAtIndexPath(indexPath) as? BudgetHomeCell {
        if let addTXView = self.storyboard?.instantiateViewControllerWithIdentifier("BHAddTXVC") as? BHAddTXVC {
            addTXView.modalPresentationStyle = .Popover
            addTXView.preferredContentSize = CGSizeMake(200, 200)
            let popover = addTXView.popoverPresentationController
            popover?.permittedArrowDirections = .Any
            popover?.delegate = self
            popover?.sourceView = cell.valueLabel
            popover?.sourceRect = cell.valueLabel.bounds
            addTXView.selectedTX = selectedItem
            self.presentViewController(addTXView, animated: true, completion: nil)
        }
    }
}

Any suggestions for better performance while presenting the popover from the value label within the table view cell? While tapping I have checked the debug navigator and there are no CPU or memory spikes. This happens both for a simulated iPad and an iPad Air 2. I did have a swipe gesture running which threw it off. I removed this and its still presenting the popup very slow in some cases.


Solution

  • Someone answered this in another post. Check it out here: https://stackoverflow.com/a/27227446/4740794

    The trick is to manually deselect the row after it is selected. It worked great for me. Make sure to use or store the selected row if needed before deselecting it.