1

In my application, i have a UIViewController that presents a UItabBarController (that has 3 NavigationControllers as tabBarItems), then i dismiss the UITabBarController from that UIViewController.

But when i present it again, the old data still shows on the tabBarController (i mean all the data that is displayed on the UIViewControllers of the NavigationControllers is still displayed). I want the UITabBarController as good as new when it is presented again. How to do this??

Here's the code: In AppDelegate.h, i made this property

@property (strong, nonatomic) UITabBarController *tabBarController;

Then, in AppDelegate.m

self.customerCareNavController = [[UINavigationController alloc] initWithRootViewController:self.custCareVC];
    self.customerCareNavController.title = @"Customer Service";

    self.purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:self.POController];
    self.purchaseOrderNavController.title = @"PO";

    self.accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:self.accAndContactsController];
    self.accAndContactsNavController.title = @"Accounts And Contacts";

    self.tabBarController = [[UITabBarController alloc] init];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.customerCareNavController, self.accAndContactsNavController, self.purchaseOrderNavController, nil];
Shradha
  • 991
  • 3
  • 13
  • 38
  • 1
    before exiting UITabbar pop all the viewcontroller and call setNeedtoDisplay will do i guess! – Retro Dec 16 '13 at 05:02
  • 1
    When you dismiss a presented controller, it should be deallocated. Since it appears that yours isn't, you must have a strong pointer to it somewhere. You should show the code where you create the tab bar controller and present it. – rdelmar Dec 16 '13 at 05:05
  • I have updated my question and added some code. Yes i have made TabBarController "strong". What should i do?? declare it as a "weak" property?? – Shradha Dec 16 '13 at 05:15
  • Actually i am a very new iOS developer and not very good with memory management concepts.. – Shradha Dec 16 '13 at 05:16

1 Answers1

1

Is there a reason you're doing this in the app delegate? If you're presenting the tab bar controller from another view controller, you should put all that code in the method where you do the presentation and don't create a property for it, or any of its controllers, just local variables. The presenting controller will keep a reference to it, so you don't need to. When you dismiss it, it and all its content controllers will be deallocated.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • done.. Thanks a lot.. Only one more problem though.. All the images on myTabBArController are gone now.. – Shradha Dec 16 '13 at 05:52
  • @Coder123, what images? When are they added to the tab bar controller. – rdelmar Dec 16 '13 at 06:34
  • yes.. but now i have removed the images that i have used for UITabBarItems and added images for UItabBar. But now, i seem to get an unwanted line on my tabbar. My problem is similar to the problem discussed in http://stackoverflow.com/questions/18785930/an-unwanted-line-on-tab-bar-controller-under-ios7 – Shradha Dec 16 '13 at 08:37
  • I have used the following code: tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]]; tabBarView.frame = CGRectMake(0, -15, 320, 64); [tabBarController.tabBar addSubview:tabBarView]; What should i change??? and what should be the dimensions of my new image that i can use for UITabBar?? – Shradha Dec 16 '13 at 08:40
  • I think teh height of the tabBarin ios 7 is 49 points.. so I guess my image should now be 320X49 pixels.. right?? – Shradha Dec 16 '13 at 08:45
  • @Coder123, I'm not really sure what you're doing. How are the images added when the app first starts up? Were they correct before you changed the code using my answer? Why are you changing the way you're adding images to the tab bar? This seems like a separate question from what you originally asked, so if you're having trouble, you should post a new question, so you can describe it more fully. – rdelmar Dec 16 '13 at 16:32
  • I have added it as a separate post.. here's the link http://stackoverflow.com/questions/20625889/image-on-tabbar-not-displaying-properly-shows-an-extra-line-on-top – Shradha Dec 17 '13 at 04:25