I need to reload the data in a view controller when it’s tabbar is clicked.
I am using the UITabBarControllerDelegate method as below:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (tabBarController.selectedIndex == 3)
{
[(SomeViewController *)viewController getData];
}
}
where ‘getData’ is an instance method in SomeViewController class. However when I run my app, I get the following error
2011-07-01 02:12:11.193 onethingaday[19169:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController getData]: unrecognized selector sent to instance 0x600d500'
Can anyone advise me how I can overcome this issue? I just need to trigger the ‘getData’ method when tabbarcontroller.selected index ==3
It seems to me from the error message you get, that you use a
UINavigationControllerin your tab controller; in this case, you cannot send directly thegetDatamessage to it; you should first find out which view controller under theUINavigationControllershould receive that message. (This is not actually related to the tab barselectedIndex)I don’t know how your UINavigationController is organized, but you could do:
If you give more details about the organization of your
UINavigationControllerI can help further identifying the right option.Anyway, as you can see from the casts, there is something that is not fully ok with your design. I would strongly suggest using a notification for that. I.e., your
SomeViewControllerregisters itself for a notification of a given type :and the tab bar controller sends the notification for your controller to react upon:
Look at this post.