gpt4 book ai didi

ios - 在检查其他方法问题之前调用 shouldPerformSegueWithIdentifier

转载 作者:行者123 更新时间:2023-11-29 10:34:13 28 4
gpt4 key购买 nike

我正在尝试进行 segue,但我有一个小问题,即我正在单击一个按钮,如果 bool 值为 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;
}
}

最佳答案

您需要从按钮中的操作中删除 segue,将其移动到 View Controller ,然后在您的 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;
}

关于ios - 在检查其他方法问题之前调用 shouldPerformSegueWithIdentifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27939361/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com