Jason
Jason

Reputation: 881

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

Upvotes: 0

Views: 734

Answers (2)

theMikeSwan
theMikeSwan

Reputation: 4729

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

Upvotes: 1

Jesse Naugher
Jesse Naugher

Reputation: 9820

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

Upvotes: 0

Related Questions