views:

188

answers:

1

OK so having a real headache with this one and most of the day has been wasted! with little progress!

The app:

  • I have a tab bar application each tab has its own view controller and associated view.
  • Say on tab 1 a user clicks on a button to go to a different view i have implemented the following: [self.view addsubView:view 2]
  • I keep adding views in this way
  • If the user returns from that view to the previous view i get rid of it with a back button linked to [self.view removefromsuperview]

Right! that all works fine... here comes the headache.

If the user completes the following: - navigates to view2 on tab 1 - switches to tab 2 - returns to tab 1 again

I would like to remove all subviews (loaded from viewControllers) so that they are presented with view1 on tab 1.

get it?

i have tried the following:

for(UIViewController *subview in [self.view subviews]) {
    if([subview isKindOfClass:[View2Controller class]]) {
        [subview.view removeFromSuperview];
    } else {
        // Do nothing
    }
}

In an attempt to remove view2. (This method is called in view1's viewWillAppear - and does get called but does not remove view2)

Any Ideas?? Any help with this issue would be highly appreciated

Cheers

A: 

I would switch to a UINavigationController based view-architecture for each tab. Then you can just push and pop viewControllers, and let the system do its part to help you manage memory. Also, you can then just call popToRootViewController when you want to jump to the 'bottom'.

Also, be sure to note that UIViews and UIViewControllers are different classes, and should NOT be used interchangeably. subviews is an array of UIViews, not UIViewControllers.

Ben Gottlieb
OK thanks for the advice.... You can see how i have set up the view-architecture of my app..... Will it be a difficult task to change this to a UINavigationController based view architecture?? The reason i decided to take the route i did was because i did not want to have the navigation bar at the top....
Tom G