views:

53

answers:

2

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;
}
A: 

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).

Jesse Naugher
Thanks for the explanation!
Jason
+1  A: 

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).

theMikeSwan