开发者

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开发者_StackOverflow社区 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜