Objective-c: start app with second view with a navigation bar

[亡魂溺海] 提交于 2019-12-08 03:18:49

问题


I'm creating an App for Ipad, I created 3 views with a navigation bar but I would to start my application not in first but in second view, what can i do?


回答1:


You can setup UINavigationController with an initial navigation stack via setViewControllers:animated:.

// in application:didFinishLaunchingWithOptions:

self.navigationController = [[UINavigationController new] autorelease];

UIViewController *first = [[MyFirstViewController new] autorelease];
UIViewController *second = [[MySecondViewController new] autorelease];
NSArray *controllers = [NSArray arrayWithObjects:first, second, nil];

[navigationController setViewControllers:controllers animated:NO];

...
[window addSubview:navigationController.view];



回答2:


Initialise your navigation controller on startup programmatically with 2 controllers already in stack:

FirstViewController *first = ...//create controller
SecondViewController *second = ...//create controller

[navigationController setViewControllers:[NSArray arrayWithObjects:first, second, nil]
                                animated:NO];

Or alternatively you can make your 1st controller push the second one on startup - see Apple's DrillDownSave sample for that technique.




回答3:


Follow somesteps as:

1.open the MainWindow.xib in resource folder or bundle.

2.click on Tool and open Inspector >> choose attribute >> NIB Name-set here your view name from drop down list >> identity in inspector(from upper tabs) >> choose class -set here your view name again from drop down list.

3.Open appdelegate.m file change here the view controller as : fileviewcontrollername *viewController; set it's property.

4.in didFinishLaunching in appdelegate.m add

UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:viewController];[window insertSubview:navController.view];[self.window makeKeyAndVisible];return YES;

5.In appdelegate.h file add

@class viewControllername;



来源:https://stackoverflow.com/questions/5487315/objective-c-start-app-with-second-view-with-a-navigation-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!