objective c - How to implement didSelectViewController -


i want catch event when switches between tabs. have following 2 function in appdelegate file:

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     uitabbarcontroller * uitbc = [storyboard instantiateviewcontrollerwithidentifier:@"tabbarcontroller"];     uitbc.delegate = self;     [self.window addsubview:uitbc.view];      return yes; }   - (void)tabbarcontroller:(uitabbarcontroller *)tabbarcontroller didselectviewcontroller:(uiviewcontroller *)viewcontroller {     nslog(@"switching"); } 

but nslog(@"switching"); never fires. xcode issues warning line uitbc.delegate = self; saying "passing appdelegate const__strong parameter of incompatible type id".

what doing wrong? i'm following accepted answer found here, except i'm instantiating tabbarcontroller form story board:

how event switch tab menu on iphone

update based on skram's suggestion, wrote appdelegate nslog(switching) still doesn't fire:

@interface johnappdelegate : uiresponder <uitabbarcontrollerdelegate> 

i updated didfinishlauchingwithoptions:

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { tabbarcontroller = self.window.rootviewcontroller.tabbarcontroller; tabbarcontroller.delegate = self; [window addsubview:tabbarcontroller.view]; } 

good thing nothing crashes. no longer et warning incompatible types. still, didselectviewcontroller doesn't fire.

in appdelegate.h file, changed line

@interface wscappdelegate : uiresponder <uiapplicationdelegate> 

to

@interface wscappdelegate : uiresponder <uiapplicationdelegate,uitabbarcontrollerdelegate> 

then in customtabbarcontroller in viewdidload function added these lines:

wscappdelegate *appdelegate = (wscappdelegate *)[[uiapplication sharedapplication] delegate]; self.delegate = appdelegate; 

then in appdelegate.m file, added function

- (void)tabbarcontroller:(uitabbarcontroller *)tabbarcontroller didselectviewcontroller:(uiviewcontroller *)viewcontroller {  nslog(@"hooray works");  } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -