操作 Sheet 需要 10 秒以上才能出现

Action Sheet Takes 10+ seconds to appear

在我的应用程序中,我有 table 视图控制器。当用户在 tableview 的最后一行键入内容时,操作 sheet 应该出现以要求注销。这是我执行此操作的代码:

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

        switch indexPath.row {
        case 0:
            //..
        case 1:
            //..
        case 2:
            //..
        case 3:

            let logOutMenu = UIAlertController(title: nil, message: "Are you sure want to logout?", preferredStyle: .actionSheet)

            let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
            let logOutAction = UIAlertAction(title: "Log out", style: .default, handler: { (UIAlertAction) in
                print("sign out")
            })

            logOutMenu.addAction(cancelAction)
            logOutMenu.addAction(logOutAction)

            self.present(logOutMenu, animated: true, completion: nil)
        default: break

        }
    }

一切正常,但是操作有奇怪的行为sheet。显示动作大约需要 10 秒(甚至更多)sheet。我在真实设备上也注意到了同样的行为。我做错了什么?

您必须在没有动画的情况下调用索引路径中的取消选择行,否则同时出现两个动画会造成混淆并延长时间

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

    switch indexPath.row {
    case 0:
        //..
    case 1:
        //..
    case 2:
        //..
    case 3:

        let logOutMenu = UIAlertController(title: nil, message: "Are you sure want to logout?", preferredStyle: .actionSheet)

        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
        let logOutAction = UIAlertAction(title: "Log out", style: .default, handler: { (UIAlertAction) in
            print("sign out")
        })

        logOutMenu.addAction(cancelAction)
        logOutMenu.addAction(logOutAction)

        self.present(logOutMenu, animated: true, completion: nil)
       // Deselect your row it will fix it
       tableView.deselectRow(at: indexPath, animated: false)
    default: break

    }
}