Tutorial :resignFirstResponder only occurs after processing is complete


I want the keyboard to go away as soon as I hit "submit" in my iphone app, and not wait until the function completes. The function takes a long time because I'm doing a synchronous HTTP request.

How come the view doesn't update until the whole function completes? I'm working in the simulator in xcode.

-(IBAction)submit:(id)sender{      [myTitle resignFirstResponder];      ...some ASIHTTP setup...      [request startSynchronous];      return;  }  


If you want to keep your current synchronous HTTP request then make these changes:

-(IBAction)submit:(id)sender{      [myTitle resignFirstResponder];      [self performSelector:@selector(delayedSubmit:) withObject:sender afterDelay:0];  }  -(void)delayedSubmit:(id)sender {      ...some ASIHTTP setup...      [request startSynchronous];      //return;  }  

I commented out return; as it is not needed in methods that don't return anything like void and IBAction (which is really void but lets IB know to pay attention to it).


it is how code is executed in threads. "Blocks" of code all get executed to the end before something like resignFirstResponder: "activates" (really completes its execution). Therefore you can either do something like delay the start of your synchronous request, or make it asynchronous (not too difficult since you are using ASIHTTP already).

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »