didSelectViewController not working. (call webservice when user clicks the Tab)

Discussion in 'iOS Programming' started by jjgraz, Apr 25, 2009.

  1. macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #1
    I have done a bit of research but can't get this thing to work. Perhaps if i post my code someone can point out the flaw.....I appreciate your help.

    As you guessed.....I have A UITabBarController, it has 5 tabs. What im trying to do is: User selects TabBar Tab number 4 and it calls webservice to update my TableView. The call to server works fine,(it has been tested in ViewDidLoad), But I want it to call to server each time the user selects the tab.........Just can't figure out the Delegate for TabBar, it appears as though the didSelectViewController method is not working properly. See my code if you think you can help....

    blt_applicationAppDelegate.h

    Code:
    #import <UIKit/UIKit.h>
    
    @interface blt_applicationAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
            UIWindow *window;
    	IBOutlet UITabBarController *rootController;
    }
    
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) UITabBarController *rootController;
    
    
    @end
    
    blt_applicationAppDelegate.m

    Code:
    #import "blt_applicationAppDelegate.h"
    #import "ViewController.h"
    
    @implementation blt_applicationAppDelegate
    
    @synthesize window;
    @synthesize rootController;
    	
    - (void)applicationDidFinishLaunching:(UIApplication *)application {   	
            [window addSubview:rootController.view];
    	[rootController setDelegate:self];
            [window makeKeyAndVisible];		
    }
    
    - (void)dealloc {
    	[rootController release];
            [window release];
            [super dealloc];
    }
    
    @end
    
    


    ViewController.h

    Code:
    
    #import <UIKit/UIKit.h>
    
    @class blt_applicationAppDelegate;
    
    @interface ViewController : UITableViewController {
    	blt_applicationAppDelegate *appDelegate;
    }
    
    @end
    

    ViewContoller.m

    Code:
    #import "ViewController.h"
    #import "blt_applicationAppDelegate.h"
    
    @implementation ViewController;
    
    - (void)tabBarController:(UITabBarController *)rootController didSelectViewController:(UIViewController *)viewController {
    	if (1 == 1)
        {
    		*********my code to call webservice*******
    	}
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    }
    
    - (void)dealloc {
    	[appDelegate release];
            [super dealloc];
    }
    
    @end
    
    
    Thank you in advance for any help.
     
  2. thread starter macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #2
    realized I declared that app delegate implements the protocol UITabBarControllerDelegate. Thus the method needs to be in appDelegate. However, any clues why following method doesn't seem to work quite right. In the XIB file I gave the viewcontrollers titles.....one of which is Item 5....why doesn't this work?

    Code:
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    	
    	if ([rootController.tabBarItem.title isEqualToString:@"Item 5"])
    
        {
    ********bunch of code which should be called if they select tabBarItem with title equal to Item 5******
    		[window addSubview:rootController.view];
    		[window addSubview:[navigationController view]];
    		}
    	else if ([rootController.tabBarItem.title isEqualToString:@"Item 4"])
    	{
    		}
    	else if ([rootController.tabBarItem.title isEqualToString:@"Item 3"])
    	{
    		}
    	else if ([rootController.tabBarItem.title isEqualToString:@"Item 2"])
    	{
    		}
    }
    
    Thank you.
     
  3. thread starter macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
  4. macrumors newbie

    Joined:
    Feb 4, 2011
    #4
    Please could you post what you got?

    Hi please could you post what you figured out I am trying to do something similar>
     

Share This Page