xcode 以编程方式展开转场

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15272192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:55:33  来源:igfitidea点击:

xcode unwind segue programmatically

iosobjective-cxcode

提问by dan

How can we do a push xcode unwind segue programmatically?

我们如何以编程方式执行 push xcode unwind segue?

I know the simple way is to use the storyboard and pull the button to the 'exit', but what I intend to do is to have some codes run first before the view is exited.

我知道简单的方法是使用情节提要并将按钮拉到“退出”,但我打算做的是在退出视图之前先运行一些代码。

回答by Alexander of Norway

To go back to the rootViewController use:

要返回 rootViewController 使用:

[self.navigationController popToRootViewControllerAnimated:(BOOL)]

Or to go to a specific controller:

或者转到特定的控制器:

[self.navigationController popToViewController:
    [[self.navigationController viewControllers]
    objectAtIndex:THEINDEXOFTHEVIEWCONTROLLERTOUNWINDTO]
    animated:YES];

For a little more detail, see my answer in this post: Push to root View controller in UIStoryboard

有关更多详细信息,请参阅我在这篇文章中的回答: 在 UIStoryboard 中推送到根视图控制器

回答by Alladinian

If you just want to execute some code before the exit (although keep it simple otherwise you'll get a UI lock until you return something), you could override canPerformUnwindSegueAction:fromViewController:withSender:on your destination controller.

如果您只想在退出之前执行一些代码(尽管保持简单,否则您将获得 UI 锁定,直到您返回某些内容),您可以覆盖canPerformUnwindSegueAction:fromViewController:withSender:目标控制器。

Something like this perhaps:

可能是这样的:

- (BOOL)canPerformUnwindSegueAction:(SEL)action 
                 fromViewController:(UIViewController *)fromViewController 
                         withSender:(id)sender
{
    // Some operation...

    return YES; // Or NO if something went wrong and you want to abort
}

Otherwise, you could actually create the segue programmatically and manage animation/unwind logic by overriding segueForUnwindingToViewController:fromViewController:identifier:.

否则,您实际上可以以编程方式创建 segue 并通过覆盖segueForUnwindingToViewController:fromViewController:identifier:.

You can find the complete documentation here

您可以在此处找到完整的文档

回答by rpledge

You can have a segue occur in code by calling this method in UIViewController

通过在 UIViewController 中调用此方法,您可以在代码中发生 segue

- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender

You'll still create the segue in your storyboard between the 2 views, just make sure you name the segue and use the exact name in the identifier parameter

您仍将在故事板中的 2 个视图之间创建转场,只需确保为转场命名并在标识符参数中使用确切名称