0

I have an TableViewController which uses a push-segue to navigate to a subview. I would like the parent-controller to be informed, when the subview has been closed. How do I do that?

Sorry, I think it's too late for me...

Ed Liss
  • 546
  • 4
  • 16
Sammy
  • 1,178
  • 1
  • 14
  • 27
  • 1
    The usual approach is to either set a completion block or a delegate in the subview controller and so that it can notify you on completion. Some hacks based on viewWillAppear and looking at the navigation viewControllers property can be used, but are more problematic as viewWillAppear is called any time the view controller is displayed (pushing or popping) Look around here some and I'm sure you'll find a duplicate question. – David Berry Feb 27 '14 at 22:41
  • You can either use a block (my preferred approach,) delegation or a notification. So many ways you can do this. But using the viewWillAppear method, like @david is saying, is way problematic... – Ed Liss Feb 28 '14 at 08:55

2 Answers2

1

Is the only way to close it to go back?

If yes, you'll know when viewWillAppear: is called.

If not, use the delegate pattern to communicate between view controllers. (See What's the best way to communicate between view controllers?)

Community
  • 1
  • 1
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • I tried both, first idea was viewWillAppear:, so it must have been really too late. I will try again tomorrow. thx – Sammy Feb 27 '14 at 21:09
0

After reading, sleeping, reading and thinking again, I think, the best way should be to do it really right ;-)

First of all, I will update my data-handling to be more 'model-driven'. I will offer the sub controller the data it needs to work (actually it fetches these on its own).
Second thing would be, that the main controller will observe this model and therefor don't need to be informed to update data because of the closing sub controller.

This is not the answer the the original questing, but it is, what I learned from the given answers. Thanks for helping me ordering the thoughts.

Better do it right from the beginning...

Sammy
  • 1,178
  • 1
  • 14
  • 27
  • Maybe the down voter feels that this is not an answer to your question (in fact, it isn't). Yet, I agree that it's the better solution to your problem. So: +1 – Nikolai Ruhe Feb 28 '14 at 10:30