view - Objective-c Nested VIewControllers -


i create app whit structure similar native application "phone" of iphone. more precise, phone application have tabbar contains:"favorites" , "recents", "contact", "keypad" , "voice mail".

when enter in tab contacts can see navigation bar , tableview. have similar structure i'm questioning myself best , correct way it?

i thinking start single view application use view controller create automatically tabbedviewcontroller create subclass of viewcontroller , used navviewcontroller.

i have

[mytabbar.view addsubview:mynavcontroller]; 

but how can set instance? once have automatically created viewcontroller , create secondviewcontroller how can set them tabviewcontroller , navviewcontroller ?

if you're using storyboards, add tab bar controller storyboard. select 1 of tab bar's child scenes , choose "embed in" - "navigation controller" xcode "editor" menu. if repeat process whichever tabs want have navigation controllers. in screen snapshot, i've added navigation controller first , third tabs, not second.

hopefully illustrates idea.

tab bar controller navigation controllers embedded


if you're determined nibs, easiest way started create new project tabbed application template (and obviously, @ next screen, uncheck "use storyboards"):

tabbed application

then open app delegate .m file , replace default didfinishlaunchingwithoptions looks like:

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];     // override point customization after application launch.     uiviewcontroller *viewcontroller1 = [[firstviewcontroller alloc] initwithnibname:@"firstviewcontroller" bundle:nil];     uiviewcontroller *viewcontroller2 = [[secondviewcontroller alloc] initwithnibname:@"secondviewcontroller" bundle:nil];     self.tabbarcontroller = [[uitabbarcontroller alloc] init];     self.tabbarcontroller.viewcontrollers = @[viewcontroller1, viewcontroller2];     self.window.rootviewcontroller = self.tabbarcontroller;     [self.window makekeyandvisible];     return yes; } 

with 1 creates separate navigation controller each tab want navigation bar (in case, i'm adding first 1 only, illustrates idea):

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];     // override point customization after application launch.     uiviewcontroller *viewcontroller1 = [[firstviewcontroller alloc] initwithnibname:@"firstviewcontroller" bundle:nil];     uinavigationcontroller *navigationcontroller1 = [[uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller1];     uiviewcontroller *viewcontroller2 = [[secondviewcontroller alloc] initwithnibname:@"secondviewcontroller" bundle:nil];     self.tabbarcontroller = [[uitabbarcontroller alloc] init];     self.tabbarcontroller.viewcontrollers = @[navigationcontroller1, viewcontroller2]; // @[viewcontroller1, viewcontroller2];     self.window.rootviewcontroller = self.tabbarcontroller;     [self.window makekeyandvisible];     return yes; } 

this relatively easy way start nib-based tabbed application. can customize there.

personally, struggle imagine why use nibs rather storyboards (unless you're trying support ios 4), illustrates both techniques.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -