If you are using UITabBarController, you can get references to its child UIViewControllers via:
[myTabBarController objectAtIndex:index];
NSLog(@"Selected view controller class type: %@, selected index: %d", [myTabBarController selectedViewController], [myTabBarController selectedIndex]);
The zero-based indexing scheme follows the order of the tabs as you've set them up, whether programmatically or through IB (leftmost tab = index 0).
Because the UIViewController reference you appear to be searching for seems to be the rootViewController (because of the way you named it; 'InitialViewController'), you can also try this in your appDelegate. This will take 5 seconds:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"self.window.rootViewController = %@", NSStringFromClass([self.window.rootViewController class]));
UIViewController *myRootViewController = self.window.rootViewController;
}
Let me know if that does the trick :)
Whether you're using a UITabBarController or UINavigationController, I'm certain one of those is your rootViewController. Once you grab the reference to it, the rest is pretty easy:
InitialViewController* myInitialViewController;
for (UIViewController *vc in [myRootViewController childViewControllers]) {
if([vc isKindOfClass:[InitialViewController class]]){
//Store this reference in a local/global variable or a property,
//or simply perform some logic on the vc pointer if you don't need to store it.
myInitialViewController = (InitialViewController *)vc; //Example & reminder to cast your reference
}
}
EDIT BASED ON NEW DETAILS FOUND IN COMMENTS:
Ok, run this code in your topViewController's viewDidLoad or viewWillAppear:
//You have to import this class in order to reference it
#import "MESHomeViewController.h"
//Global variable for storing the reference (you can make this a property if you'd like)
MESHomeViewController *myHomeVC;
int i = 0;
for (UIViewController *vc in [self.slidingViewController childViewControllers]) {
NSLog(@"Current vc at index %d = %@", i, [vc class]);
if ([vc isKindOfClass:[MESHomeViewController class]]) {
NSLog(@"Found MESHomeViewController instance - [[self.slidingViewController childViewControllers] objectAtIndex:%d]", i);
myHomeVC = vc;
break;
}
i++;
}
See if the reference is available to you there. If it is, your console will print out the class name of your HomeViewController.