1

I have three view controllers pushed in navigationcontroller on the third one i used the statement

[self.navigationController popToViewController:(Main_View*) mainViewObj animated:YES];

It takes me directly to my specified controller say first. I have done some coding to remove objects from an NSMutableDictionary in viewWillDisappear method in all view controllers, i tried debugging using break points but it never comes to viewWillDisappear, it takes me directly to Main_View. Should i be worried about removing objects from dictionary or releasing it?

jrturton
  • 118,105
  • 32
  • 252
  • 268
Hassy
  • 5,068
  • 5
  • 38
  • 63
  • write in - (void)viewDidDisappear:(BOOL)animated – Manu Apr 05 '13 at 12:08
  • I tried but only viewDidDisappear of the last view controller is being called. – Hassy Apr 05 '13 at 12:12
  • Dude when popping the view automatically your NSMutableDictionary will be released. – Manu Apr 05 '13 at 12:14
  • Yes it will be, soo what about my other tasks like removing objects from it or for example i want to perform some other tasks too in that case? should i be avoiding poptoviewcontroller and use sequence popviewcontroller instead? – Hassy Apr 05 '13 at 12:16
  • What is your requirement ? – Manu Apr 05 '13 at 12:17
  • Actually i am using arc so i don't need to worry abt memory management but when a view disappears i need to do some tasks like removing objects from NSMutableDictionary. For future reference when i need to do more then removing objects can i use poptoviewcontroller? – Hassy Apr 05 '13 at 12:21
  • When you push new `UIViewController`, previous `UIViewController`'s `viewWillDissappear` is called. so when you do `popToViewContorller`. it'll not be called, since the view ins't appeared again. – Adil Soomro Apr 05 '13 at 12:23
  • Yes exactly, So Adil what will be the best approach to do some tasks to other viewcontrollers in that case? – Hassy Apr 05 '13 at 12:25
  • Are you using ARC? or non-ARC? – Adil Soomro Apr 05 '13 at 12:25
  • i am trying to do for both – Hassy Apr 05 '13 at 12:31

2 Answers2

2

The viewWillDisappear: method is not called for the other view controllers because they have already disappeared when you were pushing view controllers on top of them. So basically, viewWillDisappear: was already called for them at an earlier point. It wouldn't make sense to call it again, because they weren't visible in the first place.

omz
  • 53,243
  • 5
  • 129
  • 141
  • Yeah but i made a check (if statement) which only get called when you do popviewcontroller, pushviewcontroller doesn't let it do my tasks, soo if not viewwilldisappear method, then what is most suitable way for that purpose? – Hassy Apr 06 '13 at 06:26
  • Depends on what you're actually trying to do... It's not really clear from your question *why* you need to remove some objects from a dictionary when a view controller is popped. Are you reusing these view controllers later? If not, you might want to do "cleanup" tasks in `dealloc` instead. Otherwise, you might want to consider subclassing `UINavigationController`. – omz Apr 06 '13 at 07:50
0

You can try to keep weak references to your NSMutableDictanories in your AppDelegate, then after poptoviewcontroller in mainViewController get them, and see, if they are nil, or not, and if not, you can remove objects from Dictionaries in your main view with that references.

Ruben
  • 290
  • 3
  • 14