3

我想知道当某些条件为假时我们如何取消程序中的转场?

下面是我的代码片段:

if ([segue.identifier isEqualToString:@"Information Segue"])
{   
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Login" inManagedObjectContext:self.managedObjectContext];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@" ANY userid==%@ AND password==%@",_loginTextfield.text, _passwordTextField.text];
    [request setEntity:entity];
    [request setPredicate:predicate];
    NSError *anyError=Nil;
    NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest:request error:&anyError];
    if ([fetchedObjects count] )
    {
        useridentered = _loginTextfield.text;
        passwordentered = _passwordTextField.text;

        InformationTVC *informationTVC = segue.destinationViewController;
        informationTVC.managedObjectContext = self.managedObjectContext;             
    }
    else
    {
       /*  want to put my cancel the segue and remain in the login view */ 
    }
}

如果有人可以指导我,那将是一个很大的帮助。

4

3 回答 3

2

看看这个线程: Conditional segue 在 UITableViewCell 上执行

基本上不是将您的 segue 直接链接到按钮,而是将其放在视图控制器之间,并将按钮链接到 IBAction,该 IBAction 将有条件地调用函数 performSegueWithIdentifier

于 2012-03-22T03:27:58.503 回答
0

转场的参考:https ://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIStoryboardSegue_Class/Reference/Reference.html 没有允许您取消转场的公共方法。

在我看来,在转场开始发生之前,根据条件决定是否进行转场会更容易,但这取决于你。

于 2012-03-12T03:13:43.167 回答
0

这里还有另一个选择:https ://stackoverflow.com/a/42161944/4791032

你可以检查它func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath)

于 2017-02-10T14:41:14.343 回答