Textfield resignFirstResponder很晚?

时间:2010-01-16 09:07:35

标签: objective-c xcode iphone-sdk-3.0 uitextfield

我有一个奇怪的问题。我在视图中有两个UItextfields和一个按钮。当我点击按钮时。我已经改变了动画块中的视图框架,但是如果有人告诉我这个,那么稍后我在这里辞职的是我的代码我会感恩的

-(IBAction)SignINClicked
{
    [Email resignFirstResponder]; //TextField
[Password resignFirstResponder];//TextField
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.10]; 
[[self view] setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[UIView commitAnimations];  
sleep(0.10);
if([Email.text isEqualToString:@""] || [Password.text isEqualToString:@""])
{
    if([Email.text isEqualToString:@""] && [Password.text isEqualToString:@""])
    {
        UIAlertView *Error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please fill email and password" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [Error show];
        [Error release];
    }       
    else if([Email.text isEqualToString:@""])
    {
        UIAlertView *Error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please fill email" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [Error show];
        [Error release];
    }
    else if([Password.text isEqualToString:@""])
    {
            UIAlertView *Error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please fill password" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [Error show];
            [Error release];
    }
}
else
{
    [AppDelegate startLoading];     
    BOOL isCorrectUser=[self logIn:Email.text Password:Password.text];
    if (isCorrectUser==TRUE)
    {
        if(checkboxSelected==1)
            [self rememberMe:YES];
        else
            [self rememberMe:NO];
        [self performSelector:@selector(ShowDashboard) withObject:nil afterDelay:5];
    }   
    else
    {
        [AppDelegate endLoading];
        UIAlertView *Error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Either user name/password is incorrect" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [Error show];
        [Error release];
    }
}

}

-(void)startLoading
{
[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
if(MyWaitViewObj==nil)
{
    MyWaitViewObj = [[MyWaitViewController alloc] initWithNibName:@"MyWaitView" bundle:nil];
}   
[NSThread detachNewThreadSelector:@selector(showMyWaitView) toTarget:self withObject:nil];
[NSThread sleepForTimeInterval:0.1];
}

-(void)endLoading
{
[MyWaitViewObj.view  removeFromSuperview];
[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
}

现在,当我点击登录按钮时,首先执行[appdelegate startloading]方法,然后执行键盘隐藏。实际上它应首先隐藏键盘,然后开始加载

1 个答案:

答案 0 :(得分:2)

尝试取出睡眠声明。如果您需要在延迟后发生某些事情,请将其置于自己的方法中并使用以下方法调用:

[self performSelector:@selector(someMethod:) withObject:nil afterDelay:someTimeDelay];