Unpredictable delay before UIPopoverController appears under iOS 8.1

前端 未结 3 1872
鱼传尺愫
鱼传尺愫 2021-02-05 11:56

This problem happens with SDK 8.1, when running under iOS 8.1, but not when running under iOS 7. It is for iPad only. The problem appears both with simulator and on a hardware d

相关标签:
3条回答
  • 2021-02-05 12:04

    I found that deselecting the row before attempting to show the popover seems to fix the problem. This may be a useful work-around, but I'm still looking for a better answer, since this may not be robust.

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:NO]; // adding this line appears to fix the problem
        [self showPopover:[tableView cellForRowAtIndexPath:indexPath]];
    }

    Note, as Yasir Ali commented, that for this workaround to work, deselect animation must be off. Almost 4 years after the original post, this behavior still affects iOS 12, and the bug report with Apple is still open - sigh.

    0 讨论(0)
  • 2021-02-05 12:15

    I had the same issue, and deselecting the cell prior to displaying the popover did nothing to resolve my issue. What did work for me was dispatching the popover code to the main queue with a minuscule delay. This produces consistent display of the popover AND allows me to keep the cell SELECTED, which is key to my UI:

    Expected UI

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
        switch actions[indexPath.row] {
        case .rename:
              .... 
        case .duplicate:
    
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.01, execute: {
                let copyController = UIStoryboard.init(name: "Actions", bundle: nil).instantiateViewController(withIdentifier: "copyToNavController")
    
                copyController.modalPresentationStyle = .popover
    
                let cell = tableView.cellForRow(at: indexPath)
                copyController.popoverPresentationController?.sourceView = cell
                if let frame = cell?.frame {
                    copyController.popoverPresentationController?.sourceRect = frame
                }
                copyController.popoverPresentationController?.permittedArrowDirections = .left
    
                self.popoverPresenter = copyController.popoverPresentationController
                self.present(copyController, animated: true, completion: nil)
            })
        default:
            break
        }
    }
    
    0 讨论(0)
  • 2021-02-05 12:15

    Many thanks for that trick. I have a TableView that displays a popover when I click on a line. My popover was displaying only after a delay, or even was requiring a double click on the line to finally show up. By adding the indicated line ([tableView deselectRowAtIndexPath: indexPath animated: NO]) the popover is displayed immediately without having to double click anymore.

    0 讨论(0)
提交回复
热议问题