Search code examples
iosuitabbaruitabbaritempushviewcontroller

How to prevent uitabbaritem from taking me to "root" controller?


In my app, I have several uiTabBarItems (like search, list of items, account). When I click on account, user is supposed to put in credentials to log in. After successful login, name of tabbaritem is changed and new view controller is pushed (Profile). However, when I click on the profile tabbaritem, login controller(root for that branch of tabbar) is presented. Is there any way to disable this navigation?

enter image description here

enter image description here


Solution

  • Ok I finally managed (with help of answer that Prajwal provided, you are getting +1 for that ) to solve this.

    All I had do was delete my navigation trace at index 0 (so my login controller gets removed from navigation stack) by using this code:

    NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
    
    // [navigationArray removeAllObjects];    // This is just for remove all view controller from navigation stack.
    [navigationArray removeObjectAtIndex: 2];  // You can pass your index here
    self.navigationController.viewControllers = navigationArray;
    

    That I found here Removing viewcontrollers from navigation stack