ios - selectedIndex UItabBarController not working -


i know gonna easy fix, reason when try fix issue other solutions, doesnt work. in app set push notifications, , i'm trying set functionality of opening app tabbaritem when app opened notifications. here code have far, please tell me if i'm using right method. i'm not experienced appdelegate.m please forgive me if wrong.

appdelegate.m

#import <corelocation/corelocation.h>  @interface appdelegate : uiresponder <uiapplicationdelegate,uitabbarcontrollerdelegate,cllocationmanagerdelegate>{  cllocationmanager *locationmanager; }   @property (strong, nonatomic) uiwindow *window;   @property(nonatomic,readonly) uitabbar *tabbar; @property(nonatomic,strong) uitabbarcontroller *tabbarcontroller; @end 

appdelegate.m

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {  uiapplication* app = [uiapplication sharedapplication]; app.networkactivityindicatorvisible = yes;  [[uiapplication sharedapplication] registerforremotenotificationtypes:(uiremotenotificationtypealert | uiremotenotificationtypebadge |uiremotenotificationtypesound)];   return yes; } - (void)application:(uiapplication*)application didreceiveremotenotification:(nsdictionary*)userinfo{ /* works fine*/ nslog(@"opening notification!!"); /*this doesnt work @ all*/ self.tabbarcontroller = [[uitabbarcontroller alloc] init]; [self.tabbarcontroller ]; self.tabbarcontroller.selectedindex = 3; /*also when nslog selectedindex gives me value "2147483647"*/ nslog(@"%i tabbar item",tabbarcontroller.selectedindex); } 

because push tab bar controller login controller, there's no way reference tab bar controller app delegate, because doesn't exist until it's pushed. way fix change structure of app. while there's nothing wrong (as in cause crash) current structure, don't putting login controllers first in line, because they're used once log in, better if go away. make tab bar controller window's root view controller, , present login controller modally, no animation, viewdidappear method of controller in first tab -- make login controller first thing user sees. when you're done login, dismiss, , first tab.

if use structure, can use suggestion set selected index:

- (void)application:(uiapplication*)application didreceiveremotenotification:(nsdictionary*)userinfo{     nslog(@"opening notification!!");     self.tabbarcontroller = self.window.rootviewcontroller;     self.tabbarcontroller.selectedindex = 3;     nslog(@"%i tabbar item",tabbarcontroller.selectedindex); } 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -