Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在检查其他方法问题之前,是否应调用标识符PerformSegueWithIdentifier_Ios_Objective C_Segue - Fatal编程技术网

Ios 在检查其他方法问题之前,是否应调用标识符PerformSegueWithIdentifier

Ios 在检查其他方法问题之前,是否应调用标识符PerformSegueWithIdentifier,ios,objective-c,segue,Ios,Objective C,Segue,我正在尝试创建一个segue,但我有一个小问题,那就是我正在单击一个按钮,如果布尔值为YES,它将在segue中返回YES,否则返回NO,但每次我必须单击两次以检查文本字段,因为它首先传递给shouldPerformSegueWithIdentifier,而它应该首先检查iAction 请问如何解决此问题 - (IBAction)search:(id)sender{ if ([_txtfld.text isEqual:@"test"]) { push = YES; //Bolean

我正在尝试创建一个segue,但我有一个小问题,那就是我正在单击一个按钮,如果布尔值为YES,它将在segue中返回YES,否则返回NO,但每次我必须单击两次以检查文本字段,因为它首先传递给
shouldPerformSegueWithIdentifier
,而它应该首先检查iAction

请问如何解决此问题

- (IBAction)search:(id)sender{

if ([_txtfld.text isEqual:@"test"]) {

    push = YES; //Bolean
}

else {

    push = NO; //Bolean
  }
}

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {

if ([identifier isEqualToString:@"SearchSegue"] && push==YES) {

    NSLog(@"Showed");
    return YES;
}
else{

    NSLog(@"Not showed");
    return NO;
  }
}

您需要从按钮中的操作中删除segue,将其移动到视图控制器,然后在
iAction
方法中调用
performsguewithidentifier
,或者只需将逻辑置于
shoulldperformseguewithidentifier
中,然后删除
iAction
方法

所以,也-

- (IBAction)search:(id)sender{

    if ([self.txtfld.text isEqual:@"test"]) {

       [self performSegueWithIdentifier:@"SearchSegue" sender:self];
    }

}
并且去掉
应该使用identifier执行segue
或者去掉
iAction
方法,只需-

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {

   BOOL ret=YES;

   if ([identifier isEqualToString:@"SearchSegue"]) {
       if (![self.txtfld.text isEqual:@"test"]) {
          ret=NO;
       }
   }
   return ret;
}