[英]Delegate / Unwind Segue at NavigationController Back Button
i have an app with three views:我有一个具有三个视图的应用程序:
When i am on the ThirdView and i click on the back button from navigation controller, i want to pass data from ThridView to SecondView.当我在 ThirdView 上并单击导航控制器的后退按钮时,我想将数据从 ThridView 传递到 SecondView。 But i don't know how to do this.
但我不知道该怎么做。
I don't want to add an extra button on my view.我不想在我的视图中添加额外的按钮。
The same when i'm on the SecondView and i want to go back to the FirstView.当我在 SecondView 并且我想回到 FirstView 时也是如此。 I can't use the method "ViewWillDisappear" because if a set a "PerformSegueWithIdentifier" on this method to pass data from SecondView to FirstView, i can't switch to ThirdView because the "ViewWillDisappear" method will be executed.
我无法使用“ViewWillDisappear”方法,因为如果在此方法上设置“PerformSegueWithIdentifier”以将数据从 SecondView 传递到 FirstView,我将无法切换到 ThirdView,因为将执行“ViewWillDisappear”方法。
Can you please help me?你能帮我么?
PS: I use the language swift 2 PS:我使用语言swift 2
In your viewWillDisappear
or viewDidDisappear
method you can check if back button is pressed by checking whether or not your view controller is moving from parent view controller.在您的
viewWillDisappear
或viewDidDisappear
方法中,您可以通过检查您的视图控制器是否从父视图控制器移动来检查是否按下了后退按钮。
override func viewWillDisappear(animated: Bool) {
if(self.isMovingFromParentViewController())
{
//Send data to previous view controller
print("Going back: Back button pressed");
}else{
print("Controller is hidden due to some other reason e.g Pushing another view controller");
}
}
I make subclass of UINavigationController because I cannot find Unwind Segue signature in UIViewController since Xcode 11.我创建了 UINavigationController 的子类,因为自 Xcode 11 以来我在 UIViewController 中找不到 Unwind Segue 签名。
@implementation CLUnwindNavigationController
- (BOOL)canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender {
return NO;
}
- (IBAction)unwindForSegue:(UIStoryboardSegue *)unwindSegue towardsViewController:(UIViewController *)subsequentVC {
}
@end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.