Wednesday, March 3, 2010

UITabBar events trigger

Today, I aimed to perform a task within a viewController when the user switched to it using a UITabBar. Not the most difficult thing to do, and I may have completely hacked it, but it seems like the simplest way.

First, each of your UIViewController classes should have been automatically generated containing the function initWithNibName. Uncomment these, and change the contents of the if-condition to your desired nib name and "nil" for bundle. This gives you a way to identify each controller from your app delegate.

Second, go into your app delegate and uncomment the function tabBarController. I have two viewControllers, one of which dons the nib name, "drive". Here's what I put in the function:


// Optional UITabBarControllerDelegate method
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if ([viewController nibName] != @"drive") {
viewController.touching = FALSE;
}
}

No comments:

Post a Comment