title: Get the correct instance of UIViewController when selecting tabview - IOS
body: <p>I'm having quite an issue with my tabview in my application. My problem is that I'm using a custom UIButton in the middle of the tabbar and then I'm calling the <code>didSelectViewController</code> delegate method of <code>UITabBarControllerDelegate</code> manually when I change the index. </p>
  
  <p>The problem is that when I want to check which viewController that has been selected I'm not getting the right instance of the viewcontroller.</p>
  
  <p>Code:</p>
  
  <pre><code>-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
      UIViewController *tempController = [tabBarController.viewControllers objectAtIndex:2];
      if (viewController == [tabBarController.viewControllers objectAtIndex:2]) //Never the same
      {
          [(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
          NSLog(@"Popping to root");
      }
  }
  </code></pre>
  
  <p>And I'm calling the method here:</p>
  
  <pre><code>-(void) notifmethod{
  
      UIViewController *cameraViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"cameraNavViewController"]; //Tried this
      //CameraNavController *viewController = [[CameraNavController alloc] init];/And this
      [self tabBarController:self didSelectViewController:cameraViewController]; //The call
      NSLog(@"This called");
  }
  </code></pre>
  
  <p>The main reason for this is that I want to <code>popToRootViewControllerAnimated:NO</code> if a certain viewcontroller is selected. Thank you for any help!</p>