简体   繁体   English

对模态ViewController被解雇做出反应

[英]React on Modal ViewController being dismissed

I have three ViewControllers and one navigation controller. 我有三个ViewController和一个导航控制器。 The Navigation Stack is: 导航堆栈为:
NavigationController-push->VC1-push->VC2. NavigationController-推> VC1,推> VC2。 VC1 can modally present VC3 in code. VC1可以以代码形式形式呈现VC3。 Its not connected via segues. 它没有通过segues连接。
VC1 - "Your current projects" VC1-“您当前的项目”
VC2 - "Details of your project" VC2-“您的项目的详细信息”
VC3 - "Create new project" VC3-“创建新项目”

When user desires to create a new project, I put a VC3 using: 当用户希望创建一个新项目时,我使用以下命令放置了VC3:

- (IBAction)newProjectButton:(id)sender {
    NewProjectViewController *newProject = [[NewProjectViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:newProject];
    [self presentViewController:navController animated:YES completion:nil];
}

I user presses "Cancel" button, I use this code: 我用户按下“取消”按钮,我使用此代码:

- (IBAction)cancelButton:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

When user presses "Done" button I want VC1 to make segue to VC2 and show new project's properties. 当用户按下“完成”按钮时,我希望VC1切换到VC2并显示新项目的属性。 I would like this segue to be invisible for user, so, he only sees this chain of events: 我希望用户无法看到此序列,因此,他只看到以下事件链:
Presses the button "add" -> modal VC appears -> presses "Done" -> Modal VC disappears and VC3 is already shown. 按下按钮“添加”->模态VC出现->按下“完成”->模态VC消失并且VC3已经显示。

What I am asking is how to tell VC1 that user pressed button "Done"? 我要问的是如何告诉VC1用户按下了“完成”按钮? Is delegation possible here? 这里可以委托吗? How to implement it? 如何执行呢? Thank you. 谢谢。

You should create a delegate protocol which allows the modal view controller to send notifications to its creator. 您应该创建一个委托协议,该协议允许模态视图控制器向其创建者发送通知。

@protocol ModalViewControllerDelegate
@optional
- (void)modalViewControllerDidCancel:(ModalViewController *)vc;
- (BOOL)modalViewControllerShouldSave:(ModalViewController *)vc;
@end

Then, in ModalViewController you define a new property. 然后,在ModalViewController定义一个新属性。 The weak is important, because you don't want to have any retain cycles. weak很重要,因为您不想有任何保留周期。

@property (nonatomic, weak) id <ModalViewControllerDelegate> delegate;

Before dismissing or saving, just check if the delegate has implemented the methods (via -respondsToSelector: ) and send the appropriate callbacks. 在关闭或保存之前,只需检查委托是否已实现方法(通过-respondsToSelector:并发送适当的回调。 Don't forget setting the delegate property when creating your modal view controller. 创建模态视图控制器时,请不要忘记设置委托属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模态窗口没有被解雇 - Modal window not being dismissed ios-如果关闭模态,如何在ViewController中调用方法 - IOS How to call a method in a ViewController if modal is dismissed ViewController 在被解雇后是否从 memory 卸载? - Is a ViewController unloaded from memory after being dismissed? 关闭模式 ViewController 时,向 UITabBar 添加按钮程序会被移动 - adding a button programatiy to UITabBar is moved when dismissed a modal ViewController 迅速。 检测何时关闭Facebook登录ViewController - Swift. Detecting when facebook login viewcontroller is being dismissed viewDidAppear调用了一个在iOS8中被解雇的viewcontroller - viewDidAppear called on a viewcontroller which is being dismissed in iOS8 调用dismissViewControllerAnimated但不解除ViewController - dismissViewControllerAnimated is called but ViewController is not dismissed 关闭模态视图(第二视图)时,刷新ViewController中的核心数据-Swift - Refresh Core Data in ViewController when Modal View (2nd view) is Dismissed - Swift 键盘不会被 React Native 中的 Keyboard.dismiss 关闭 - Keyboard not being dismissed with Keyboard.dismiss in React Native viewController我解雇时存在 - viewController Present when I dismissed it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM