推送segue呼叫两次

时间:2014-04-05 06:21:12

标签: objective-c ios7

我正在使用故事板。对于push segue的验证,我正在使用“ - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)标识符发送者:(id)发送者”这个方法,但它调用两次意味着在2次点击后打开下一个视图,此方法也调用了2次,我无法找到问题所在。任何人都可以帮我解决这个问题。

这是我的代码 -

-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
 if ([identifier isEqualToString:@"pushTab"])
 {
   if ([emailTxt.text isEqualToString:@""] || [passwordTxt.text isEqualToString:@""])             
   {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Please               
        put your id or password" delegate:nil cancelButtonTitle:@"OK" 
        otherButtonTitles:nil];
        [alert show];
        return NO;
    }
    else
    {
        emailText = emailTxt.text;
        passwordText = passwordTxt.text;
        Login *loginModel = [[Login alloc]init];
        [ASKevrOperationManager login:loginModel handler:^(id object , NSError *error 
        , BOOL success)
         {
             if (success) 
             {
                 flag = true;
                 NSLog(@"Successful data = %@",object);
             }
             else
             {
                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
                 message:@"Wrong Id or Password" delegate:nil cancelButtonTitle:@"OK" 
                 otherButtonTitles:nil];
                 [alert show];
                 flag = false;
                 NSLog(@"Invalid Data");
             }
         }];
        if (flag == true) {
            return YES;
        }
    }
}
return NO; }

1 个答案:

答案 0 :(得分:0)

尝试使用此方法,

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
 //Stuff
}