views:

241

answers:

1

Hello all,

I have one strange problem.I have two UItextfields in my view and a button.When i click on button.I have changed the frame of view in animation block but it's resigning later here is my code if someone told me about this i'll be thankful

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

Now when i click on signin button the [appdelegate startloading] method executes first and then keyboard hides.While actually it should hide the keyboard first and then start loading

+1  A: 

Try taking out the sleep statement. If you need something to happen after a delay, put it in it's own method and call it with:

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