xcode - My code is not Queuing as what I want -



xcode - My code is not Queuing as what I want -

i have app build on xcode, there button logout user , contain code below, have no problem it:

self.lbgoodbye.text = @"goodbye"; nsstring *post =[[nsstring alloc] initwithformat:@"myqasidaname=%@",[self.textusername text]]; nslog(@"postdata: %@",post); nsurl *url=[nsurl urlwithstring:@"http:/mywebsite/logoutuserdefaults.php"]; nsdata *postdata = [post datausingencoding:nsasciistringencoding allowlossyconversion:yes]; nsstring *postlength = [nsstring stringwithformat:@"%lu", (unsigned long)[postdata length]]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init]; [request seturl:url]; [request sethttpmethod:@"post"]; [request setvalue:postlength forhttpheaderfield:@"content-length"]; [request setvalue:@"application/json" forhttpheaderfield:@"accept"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [request sethttpbody:postdata]; nserror *error = [[nserror alloc] init]; nshttpurlresponse *response = nil; nsdata *urldata=[nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; nslog(@"response code: %ld", (long)[response statuscode]); if ([response statuscode] >= 200 && [response statuscode] < 300) { nsstring *responsedata = [[nsstring alloc]initwithdata:urldata encoding:nsutf8stringencoding]; nslog(@"response ==> %@", responsedata); nsstring *url = [nsstring stringwithformat:@"http:/mywebsite/logoutuserdefaults.php?qasidaname=%@",[self.textusername text]]; nsdata *data =[[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:[url stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]]]; self.jasonarray = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:nil]; [self performseguewithidentifier:@"gotomain" sender:self];

i have label , want utilize message goodbye user, problem when set code @ begging, not work till rest of code finished.

i not sure if have problem xcode, tried build new app still have same problem, using xcode 6.0.1 , started build app using xcode 5.

i new xcode , not have much experience sort out problem.

can help me?

you did code in main thread of application thats why until process not completing not display label changes on screen.

use background thread phone call logout web service. below illustration of phone call api in background.

dispatch_async(dispatch_get_global_queue( dispatch_queue_priority_default, 0), ^(void){ //background thread add together logout api phone call here dispatch_async(dispatch_get_main_queue(), ^(void){ //run ui updates [self performseguewithidentifier:@"gotomain" sender:self]; add together code on here }); });

xcode

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -