0

I have a two scene StoryBoard in my app - it uses an automatic segue (created in IB). When a button is clicked in the 1st UIViewController the 2nd UIViewController is presented modally.

The 1st UIViewController needs to know when second the 2nd UIViewController dismisses itself. What is the correct way to achieve this? Right now, I'm using -viewDidAppear: in the 1st vc but that doesn't seem right.

Any pointers would be much appreciated.

Best, CS

4

3 回答 3

1

只需按照 Apple 使用 SDK 提供的旨在以模态方式呈现的 ViewController 的方式进行操作:MFMailComposer、UIImagePicker 等。

使用委托。

于 2012-10-19T18:24:22.693 回答
1

您可以使用通知来确保您仅在 vc2 解雇时执行任务。

// in vc1
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomethingWhenVC2Dismissed) name:@"vc_2_dismissed" object:nil];

// in vc2
[[NSNotificationCenter defaultCenter] postNotificationName:@"vc_2_dismissed" object:nil];
于 2012-10-19T12:52:46.777 回答
1

你在做什么,加上检查isMovingToParentViewController是否,应该适用于这种特定情况。如果您曾经有其他从第一个触发的视图控制器并且您想要区分它们,这将无济于事。

最直接的方法是让模态控制器在它消失时发布通知。

于 2012-10-19T12:22:25.557 回答