1

I have a problem. I am working on an app which is tab bar based app. In this app, we call [self.view addSubview:newVC.view] when we want to navigate to a new view. newVC is the view controller of the new view that we want to display. Also we use [self.view removeFromSuperview] when we want to go back to previous view.

So in other words, there is no navigation controller. Now problem is that I want to update the previous view. Since we are using [self.view removeFromSuperview], viewDidAppear of the previous view is not get called and so we have no way of refreshing that view.

I know the approach that we used has flaw but since its a large scale app and changing it to implement navigation controller with take lot of time so I need you to please help me find the solution of this problem. How can I call the viewDidLoad or viewDidAppear or the previous view on calling [self.view removeFromSuperview] from its subview?

Knossos
  • 15,802
  • 10
  • 54
  • 91
Aqueel
  • 1,246
  • 3
  • 23
  • 46
  • i think you can try this `[super viewDidLoad]` before `[self.view removeFromSuperview]`. I have not try this but i think this will work – Mobile App Dev Sep 13 '11 at 06:29
  • You should NEVER call viewDidLoad yourself. This will be called for you after your view has loaded. Terrible things will happen if you call it manually, especially if the view actually hasn't been loaded. – Mike Weller Sep 13 '11 at 07:06
  • why don't you take reference of the parent view controller to the sub view and manipulate it by calling a method you implement specific for the things you would like to take care on it? – Saran Sep 13 '11 at 07:13

2 Answers2

0

viewDidLoad method call only when when you jump into a controller through pushViewController method. If you call removeFromSupreView, it will call viewWillAppear method. Here if you want to navigate from one view to another view over tabbar you must use UINavigationController in Mainwindow.xib and connect its viewController with App delegate.

Knossos
  • 15,802
  • 10
  • 54
  • 91
kulss
  • 2,057
  • 1
  • 14
  • 16
0

Yes, as Sarah said you should hold a reference to previous controller in "stack". And when "poping" controller from stack, call appropriate method on previous controller. Certainly you should not call viewDidLoad (it is not called when you pop controller from navigation stack of real UINavigationController). You can call viewWillAppear or viewDidAppear, but better use your own method, like viewRevealed (you can also call it from viewWillAppear or viewDidAppear). It is useful to make base class where implement all this functionality and derive all you controller from the base class. It may look like:

- (void) pushViewController:(BaseViewController *)baseController{
  [self.view addSubview:baseController.view];
  baseController.parentController = self;
}
- (void) pop{
  [self.view removeFromSuperview];
  [self.parentController viewRevealed];
}
Ravi Gautam
  • 960
  • 2
  • 9
  • 20
Vladimir
  • 7,670
  • 8
  • 28
  • 42