Unpredictable delay before UIPopoverController appears under iOS 8.1

前端 未结 3 1912
鱼传尺愫
鱼传尺愫 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: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
        }
    }
    

提交回复
热议问题