Search code examples
uiviewcontrolleruitabbarcontrollerdetailview

how to find current loaded viewcontroller?


I have an tabBarController app with 2 tabBarItems. each viewControllers contains tableView.
On didSelectRowAtIndexPath i am loading the detailview with this lines of code:

detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:[NSBundle mainBundle]];

detailViewController.selectedDetail = [selectedDetail valueForKey:@"cardText"];
detailViewController.selectedCardTitle2 = [selectedCardTitle valueForKey:@"cardTitle"];
detailViewController.selectedRow2 = [self.tableViewInbox indexPathForSelectedRow];
detailViewController.detailCardsArray = allCards;
detailViewController.detailAllFetchedCards = allFetchedCards;

detailViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[inboxViewController presentModalViewController:detailViewController animated:YES];

Problem is, when detailView is loaded(is the actual shown viewController) and i change to the other tabBarItem, the detailView DOES NOT DISMISS. That means, that i cant load the detailView again, if didSelectRowAtIndexPath is called.

In my AppDelegate i have the method

- (void)tabBarController:(UITabBarController *)tabBarController  didSelectViewController:(UIViewController *)viewController {  

In this method i will check up, if the detailView is the actual shown viewController.
And if it is, and the tabBarItem changes, THEN dismiss the DetailView.

Now my question is: How can I CHECK, if the detailView is loaded (current shown view) or not?


Solution

  • The documentation tells us that the detailView becomes a child of the presenting view. The presenting view controller will have it's modalViewController property updated to point to the presented view. Also, the modal view's parentViewController will be updated to point to the presenting view.

    So, you could check these properties to see whether or not the modal view is displayed or not.