iphone - Is there a way to remove of add a tab to a tab bar dynamically while using the app in iOS? -
i have tab bar 5 tabs on in app. final tab shows ads. want add setting user can turn 5th tab "off".... remove screen.
note don't want hide it, want remove it, 4 remaining tabs evenly spaced automatically.
i want same adding tab in.
is possible without user having restart app?
you need use uitabbarcontroller's viewcontrollers property.
use code remove last view controller:
nsmutablearray *mutableviewcontrollers = [tabbarcontroller.viewcontrollers mutablecopy]; [mutableviewcontrollers removelastobject]; tabbarcontroller.viewcontrollers = mutableviewcontrollers;
use code restore last view controller when needed:
nsmutablearray *mutableviewcontrollers = [tabbarcontroller.viewcontrollers mutablecopy]; [mutableviewcontrollers addobject:previouslyremovedviewcontroller]; tabbarcontroller.viewcontrollers = mutableviewcontrollers;
of course example assumes have reference tabbarcontroller, , keep lastviewcontroller (on property example).
also, make sure run code on main thread.
Comments
Post a Comment