Stafford Williams February 2016

Updating UI as the result of a request handler

I have a setup like this;

startup() {
    ...
    self.gcdWebServer.addHandlerForMethod("GET", path: "/hide", 
        requestClass: GCDWebServerRequest.self, asyncProcessBlock: {request in self.hide()})
    ...
}

func hide() -> GCDWebServerDataResponse {
    self.view.hidden = true;
    print("hide")
    return GCDWebServerDataResponse(statusCode: 200)
}

When a request to /hide is made, the console shows the print() call immediately, but the view does not disappear for some arbitrary delay, somewhere between 10-30 seconds.

How can I have the request immediately result in the view being hidden?

Answers


Greg February 2016

Wrap you r UI related login inside dispatch async and run it on main thread:

dispatch_async(dispatch_get_main_queue(),{

    self.view.hidden = true;

 })


turushan February 2016

Try this one, calling hidden on main thread.

dispatch_async(dispatch_get_main_queue(),{
   self.view.hidden = true;
})


Hitendra Hckr February 2016

Rewrite your hide method as below. You need update UI on main thread only.

func hide() -> GCDWebServerDataResponse {
    dispatch_async(dispatch_get_main_queue(),{
        self.view.hidden = true
    })
    print("hide")
    return GCDWebServerDataResponse(statusCode: 200)
}


Aruna kumari February 2016

UI update code write in main thread only.

 dispatch_async(dispatch_get_main_queue(),{

        self.view.hidden = true;

     })

Post Status

Asked in February 2016
Viewed 3,209 times
Voted 6
Answered 4 times

Search




Leave an answer