ios7 - iOS 7 Tab bar icons temporarily disappear when on More tab -
when add view controller embedded navigation controller, tab bar, icon + title disappear briefly when coming more tab.
however when view controller added such, icon+image okay , don't disappear.
i've tried many things already, , out of options. ideas?
here's appdelegate
code:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; self.tabbarcontroller = [[uitabbarcontroller alloc] init]; // must placed here, before tabs added. otherwise navigation bar // overlap status bar. [[uiapplication sharedapplication] setstatusbarhidden:no withanimation:uistatusbaranimationslide]; [self addviewcontrollerstotabbar]; self.window.rootviewcontroller = self.tabbarcontroller; self.window.backgroundcolor = [uicolor whitecolor]; [self.window makekeyandvisible]; return yes; } - (void)addviewcontrollerstotabbar { nsarray* tabbarclassnames = @[ nsstringfromclass([firstviewcontroller class]), nsstringfromclass([secondviewcontroller class]), nsstringfromclass([firstviewcontroller class]), nsstringfromclass([firstviewcontroller class]), nsstringfromclass([firstviewcontroller class]), nsstringfromclass([secondviewcontroller class]), nsstringfromclass([firstviewcontroller class]), ]; nsmutablearray* viewcontrollers = [nsmutablearray array]; (nsstring* classname in tabbarclassnames) { uiviewcontroller* viewcontroller = [[nsclassfromstring(classname) alloc] init]; uinavigationcontroller* navigationcontroller; navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller]; [viewcontrollers addobject:navigationcontroller]; } [viewcontrollers addobject:[[firstviewcontroller alloc] init]]; // 1 fine. self.tabbarcontroller.viewcontrollers = viewcontrollers; self.tabbarcontroller.selectedviewcontroller = viewcontrollers[2]; }
and view controllers literally nothing more than:
@implementation secondviewcontroller - (instancetype)init { if (self = [super init]) { self.title = @"second"; self.tabbaritem.image = [uiimage imagenamed:@"second.png"]; } return self; } @end
holy shit, spent time on bug, here's workaround. instead of:
navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller];
i created own navigationcontroller
subclass of uinavigationcontroller
:
@implementation navigationcontroller - (instancetype)initwithrootviewcontroller:(uiviewcontroller*)rootviewcontroller { if (self = [super initwithrootviewcontroller:rootviewcontroller]) { nsstring* classname = nsstringfromclass([rootviewcontroller class]); nsstring* name = [classname stringbyreplacingoccurrencesofstring:@"viewcontroller" withstring:@""]; self.tabbaritem.image = [uiimage imagenamed:[nsstring stringwithformat:@"%@tab.png", name]]; } return self; } @end
and do:
navigationcontroller = [[navigationcontroller alloc] initwithrootviewcontroller:viewcontroller];
prerequisite tab images have same base name view controller class name, case in app.
i setting self.tabbaritem.image
inside view controllers' init
method, , seems cause effect seeing. in addition using own navigation controller, deleted setting tabbaritem
in each individual view controller.
Comments
Post a Comment