简体   繁体   English

父视图 controller 中是否有在模态视图被关闭后被调用的委托?

[英]Is there a delegate in the parent view controller that gets called after a modal view gets dismissed?

After a modal view controller is dismissed, is there any delegate method called to bring the parent view controller to the front?在模态视图 controller 被解除后,是否调用了任何委托方法将父视图 controller 带到前面?

I ended up using delegation from Apple's View Controller Programming Guide for iOS:我最终使用了 Apple 的 View Controller Programming Guide for iOS 的委托:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14 http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14

When it comes time to dismiss a modal view controller, the preferred approach is to let the parent view controller do the dismissing.当需要关闭模态视图 controller 时,首选方法是让父视图 controller 进行关闭。 In other words, the same view controller that presented the modal view controller should also take responsibility for dismissing it whenever possible.换句话说,呈现模态视图 controller 的同一视图 controller 也应该负责尽可能地关闭它。 Although there are several techniques for notifying a parent view controller that it should dismiss its modally presented child, the preferred technique is delegation.尽管有几种技术可以通知父视图 controller 它应该关闭其模态呈现的子视图,但首选技术是委托。

There was a good example in the CoreDataRecepies sample code when adding a recipe that fit what I was trying to do.添加适合我尝试做的食谱时,CoreDataRecepies 示例代码中有一个很好的示例。

ie, at the "same time" view[Will|Did]Disappear: is being called on the modal view controller as its view is being dismissed, the view[Will|Did]Appear: are sent to the view controller that is being revealed即,在“同时” view[Will|Did]Disappear:在模态视图controller 上被调用,因为它的视图被关闭, view[Will|Did]Appear:被发送到正在显示的视图controller

the code in here should not really need to differ from the reveal code you used when it was first displayed,这里的代码不应该与你第一次显示时使用的显示代码不同,

if you need data passed back from the modal controller to the one that displayed it, generally the code that dismisses the modal controller lets the other one know如果您需要从模态 controller 传回的数据到显示它的那个,通常关闭模态 controller 的代码会让另一个知道

parentController.item = self.chosenItem;
[parentController dismissModal…

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM