i have uibutton
in login view controller when pressed, fetches value uitextfield
, performs post request server, via afnetwork
. wanna hide text field , display uiactivityindicatorview
right after button pressed, user sees happening.
the problem is, request asynchronous , happens before can update ui. please me find way achieve desired behavior
pwdtextfield.hidden = true // start activity indicator activityindicator.startanimating() // how can make happen before actual request? let token = pwdtextfield.text.trim() let requesturl = "https://myapi.com/authenticate/" manager.post(requesturl, parameters: [ "code" : token ], success: { (operation: afhttprequestoperation!, responseobject: anyobject!) in nslog("success! response \(responseobject.description)") }, failure: { (operation: afhttprequestoperation!, error: nserror!) in println("failure! error is: \(error.localizeddescription)") self.displayloginattemperroralert() }).waituntilfinished()
remove waituntilfinished().. blocks execution of current thread until operation object finish task..
manager.post(requesturl, parameters: [ "code" : token ], success: { (operation: afhttprequestoperation!, responseobject: anyobject!) in nslog("success! response \(responseobject.description)") }, failure: { (operation: afhttprequestoperation!, error: nserror!) in println("failure! error is: \(error.localizeddescription)") self.displayloginattemperroralert() })