I have the problem that many already have reported, didSelectViewController doesn\'t get called, but in my case it sometimes gets called. I have three tabs and thre
It's hard to follow what exactly you are doing, but from what I understand you are responding to tab switches by changing the UITabBarController's delegate back and forth between SecondViewController and ThirdViewController.
If that is true, I would advise against doing this. Instead I would suggest you try the following:
tabBarController: didSelectViewController:.SecondViewController and ThirdViewController instances. If you are designing your UI with Interface Builder, you might do this by adding two IBOutlets to the delegate class and connecting the appropriate instances to the outlets.tabBarController: didSelectViewController: it can simply forward the notification to either SecondViewController or ThirdViewController, depending on which of the tabs was selected.A basic code example:
// TabBarControllerDelegate.h file
@interface TabBarControllerDelegate : NSObject
{
}
@property(nonatomic, retain) IBOutlet SecondViewController* secondViewController;
@property(nonatomic, retain) IBOutlet ThirdViewController* thirdViewController;
// TabBarControllerDelegate.m file
- (void) tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController
{
if (viewController == self.secondViewController)
[self.secondViewController doSomething];
else if (viewController == self.thirdViewController)
[self.thirdViewController doSomethingElse];
}
EDIT
Some hints on how to integrate the example code from above into your project:
TabBarControllerDelegate to the .xib file that also contains the TabBarControllerdelegate outlet of TabBarController' to the TabBarControllerDelegate instancesecondViewController outlet of TabBarControllerDelegate to the SecondViewController instancethirdViewController outlet of TabBarControllerDelegate to the ThirdViewController instance- (void) doSomething to SecondViewController- (void) doSomethingElse to ThirdViewControllerSecondViewController and ThirdViewController changes the TabBarController delegate!Once you are all set and everything is working fine, you will probably want to cleanup a bit:
doSomething and doSomethingElse to something more sensiblesecondViewController and thirdViewController outlets