开发者

ViewDidAppear is not called in tab bar based app

开发者 https://www.devze.com 2023-04-04 23:23 出处:网络
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 th开

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 th开发者_运维问答e 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?


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];
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消