在推入封闭内部后,ViewController在长时间延迟后推动

时间:2017-01-10 11:59:24

标签: ios swift navigation closures

在着陆页中,我使用了一个闭包来接收来自助手类的api响应。一旦我收到响应,我就会导航到另一个页面。控件执行pushViewController行,但导航需要很长时间。是因为关闭?我该如何解决?

class LandingView: UIViewController
{    
override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    getStaticCountryAndStateList()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Navigation
func getStaticCountryAndStateList()
{
    WebAPIHelper.getMethod(methodName: "/Common/GetStaticCountryAndStateList", success: {(response)->Void in

let signInObj = SignIn(nibName: (UIDevice.current.userInterfaceIdiom == .pad ? "SignIn" : "SignIn_iPhone"), bundle: nil)
            DispatchQueue.main.async
                {
                    self.navigationController?.pushViewController(signInObj, animated: true)
            }


    }, Failure: {
        (error)->Void in
        print("Error \(error)")
    })
}
}

3 个答案:

答案 0 :(得分:1)

HasChanged

答案 1 :(得分:0)

始终在主线程中执行与UI相关的内容。

 dispatch_async(dispatch_get_main_queue(), ^{
        //update UI
 });

Swift 3

DispatchQueue.main.async {
        // update ui
    }

答案 2 :(得分:0)

推送主线程上的视图与Web请求不在同一个线程上。