ios - UITabBarControllerDelegate action not called -



ios - UITabBarControllerDelegate action not called -

it looks lot of new ios developers have problems objective c class. i'm trying observe of 5 tab items tapped (home, products, cart, search, more). based on index tapped (0, 2, 4), want display root view, if there other views stacked on top of it. here's appdelegate.h code:

@interface appdelegate : uiresponder <uiapplicationdelegate, uitabbarcontrollerdelegate> { uitabbarcontroller *tabbarcontroller; } @property (strong, nonatomic) uiwindow *window; @property (strong, nonatomic) uitabbarcontroller *tabbarcontroller; @end

appdelegate.h code :

@synthesize tabbarcontroller; - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.tabbarcontroller.delegate = self; homecoming yes; } - (void)tabbarcontroller:(uitabbarcontroller *)tabbarcontroller didselectviewcontroller:(uiviewcontroller *)viewcontroller{ nslog(@"action called."); }

you can accomplish calling selected view controller's -poptorootviewcontrolleranimated: method within tab bar controller's delegate method:

- (void)tabbarcontroller:(uitabbarcontroller *)tabbarcontroller didselectviewcontroller:(uiviewcontroller *)viewcontroller { nsuinteger vcindex = [[tabbarcontroller viewcontrollers] indexofobject:viewcontroller]; bool shouldpop = (vcindex == 0 || vcindex == 2 || vcindex == 4); if (shouldpop && [viewcontroller iskindofclass:[uinavigationcontroller class]]) { [(uinavigationcontroller *)viewcontroller poptorootviewcontrolleranimated:yes]; } }

keep in mind, though, may not best user experience – users expect can switch between tabs without losing position or state when returning tab. popping root view controller throw away state, can lead frustration.

ios objective-c cocoa-touch

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -