Connecting actions (methods) to tab bar item

Discussion in 'iOS Programming' started by jonanders89, Jun 17, 2011.

  1. jonanders89 macrumors newbie

    Jun 14, 2011

    I've googled and googled, and dont seem to find any complete answer to my question.

    I can't find the solution to how i can add actions to my tab bar items.

    I have a Delegate class:
    @interface MyProjectAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
        UIWindow *window;
        UITabBarController *rootController;
    and the implementation

    #import "MyProjectAppDelegate.h"
    @implementation MyProjectAppDelegate
    @synthesize window;
    @synthesize rootController;
    #pragma mark -
    #pragma mark Application lifecycle
    -(void) applicationDidFinishLaunching:(UIApplication *)application{
    	[window addSubview:rootController.view];
    	[window makeKeyAndVisible];
    and i've created seperate classes(with XIB files) for each tab bar item. The switching between views works beautifully. The problem is however, when someone select a view, i want the content in that view to be refreshed.

    I've seen the documentation, and especially tried to understand the didSelectItem method, but i cant figure out how its working. Can someone please push me in the right direction? I dont understand how the methods in the delegate class can acess the content in another view?
  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    2 ways you can "try" to achieve what u wan't, because I don't know what u mean, by "refreshed".

    You probably have some code in your viewDidLoad.
    you want to put that in the viewWillAppear. That is the first try.
    But also in the delegate methods of UITabbarController (if u just Command clicked it..) u see there are some methods u could MAYBE use?
    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
    - (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers
    - (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:
    - (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed;
    There are some choices.
    Especially the one called, didSelectViewController.
    U could maybe add code there..
  3. jonanders89 thread starter macrumors newbie

    Jun 14, 2011
    Ahh, my question was bad formulated.

    What i meant, is that i have a textView in one of my views. That view is selected from a tab bar item. My goal is that whenever a user selects that view from the tab bar, i want to call an action that handles myTextView.

    So, i need to add an action to that tabBarItem, but i can acess that action in my Tab Bar, since that action is decleared within another view (another class file)
  4. jonanders89 thread starter macrumors newbie

    Jun 14, 2011
    Solved with another solution. Added my code for the respective view in the viewWillAppear method instead.

Share This Page