ios - Creating UITabBarController in a UINavigationController -
my app has drawer menu view , content views.
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { uistoryboard *storyboard = [uistoryboard storyboardwithname:@"main" bundle:nil]; // side menu view controller uiviewcontroller *menuviewcontroller = [storyboard instantiateviewcontrollerwithidentifier:@"sidebar_menu"]; uinavigationcontroller *menunav = [[uinavigationcontroller alloc] initwithrootviewcontroller:menuviewcontroller]; // initial content view controller uiviewcontroller *contentviewcontroller = [storyboard instantiateviewcontrollerwithidentifier:@"content1"]; uinavigationcontroller *contentnav = [[uinavigationcontroller alloc] initwithrootviewcontroller:contentviewcontroller]; nvslidemenucontroller *slidemenucontroller = [[nvslidemenucontroller alloc] initwithmenuviewcontroller:menunav andcontentviewcontroller:contentnav]; slidemenucontroller.slidedirection = nvslidemenucontrollerslidefromrighttoleft; self.window.rootviewcontroller = slidemenucontroller; [self.window makekeyandvisible]; }
i want insert tab bar controller programatically content view. want change current content view content view when tab bar item button pressed.
is possible create kind of structure? how achieve this?
you need code you've described in question. here how can modify code add uitabbarcontroller
wraps contentviewcontroller
, i've changed the initial content view controller section:
// initial content view controller uiviewcontroller *contentviewcontroller = [storyboard instantiateviewcontrollerwithidentifier:@"content1"]; [contentviewcontroller settabbaritem:[[uitabbaritem alloc] initwithtitle:@"my content" image:[uiimage new] tag:1]]; uitabbarcontroller *tabbarcontroller = [[uitabbarcontroller alloc] init]; [tabbarcontroller setviewcontrollers:@[contentviewcontroller/* can add more view controllers if needed*/]]; uinavigationcontroller *contentnav = [[uinavigationcontroller alloc] initwithrootviewcontroller:tabbarcontroller];
Comments
Post a Comment