在检查其他方法问题之前调用了shouldPerformSgueWithIdentifier.

本教程将介绍在检查其他方法问题之前调用了shouldPerformSgueWithIdentifier.的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。

在检查其他方法问题之前调用了shouldPerformSgueWithIdentifier. 教程 第1张

问题描述

我正在尝试分段,但我有一个小问题,那就是我正在单击一个按钮,如果布尔值为yes,则它将在Segue中返回yes,否则返回no,但每次我都必须单击两次才能检查文本字段,因为它首先传递给shouldPerformSegueWithIdentifier,而它应该首先检查IBAction。

请告诉我怎么解决此问题?

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

推荐答案

您需要从按钮中的操作中删除段,将其移动到视图控制器,然后在IBAction方法中调用performSegueWithIdentifier,或者只在shouldPerformSegueWithIdentifier中具有逻辑并删除IBAction方法。

所以,要么-

- (IBAction)search:(id)sender{

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

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

}

并去掉shouldPerformSegueWithIdentifier或去掉IBAction方法而只有-

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

BOOL ret=YES;

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

好了关于在检查其他方法问题之前调用了shouldPerformSgueWithIdentifier.的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。