[英]xcode unwind segue programmatically
How can we do a push xcode unwind segue programmatically? 我们怎样才能以编程方式推送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. 我知道简单的方法是使用故事板并将按钮拉到“退出”,但我打算做的是在退出视图之前先运行一些代码。
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中按下查看控制器
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:
. 否则,您实际上可以通过重写
segueForUnwindingToViewController:fromViewController:identifier:
以编程方式创建segue并管理动画/展开逻辑。
You can find the complete documentation here 您可以在此处找到完整的文档
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 您仍然会在两个视图之间的故事板中创建segue,只需确保命名segue并使用identifier参数中的确切名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.