如何替换“基于导航的应用程序”中的RootViewController
我有一个在 XCode 中使用“基于导航的应用程序”模板的应用程序。
现在我想更改它,以便加载的第一个视图是常规(自定义)UIView,如果用户单击特定按钮,我会将原始 RootViewController 推送到 NavigationController 上。
我知道在某个地方,有人用我的 RootViewController 调用它:
- (id)initWithRootViewController:(UIViewController *)rootViewController
我想知道如何用我的新类替换参数。
I have an application that uses the "navigation-based application" template in XCode.
Now I want to change it so that the first view that loads is a regular (custom) UIView, and if the user clicks a particular button, I push the original RootViewController onto the NavigationController.
I understand that somewhere, someone is calling this with my RootViewController:
- (id)initWithRootViewController:(UIViewController *)rootViewController
I want to know how to replace the argument with my new class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想替换导航堆栈的根视图控制器,您可以将其视图控制器数组的第一个对象替换为 -
if you want to replace the root view controller of your navigation stack you can replace the first object of its view controllers array as -
^ 这些都是以编程方式完成的方法。这很酷。但我在 Xcode 中使用界面生成器和故事板,因此这是添加新视图控制器的简单快捷方法:
Tada!享受新的根视图控制器,而无需因编程创建而耽误您的一天。
^ These are all ways to do it programmatically. Thats cool. But I use the interface builder and storyboards in Xcode, so this is the easy and fast way to add a new view controller:
Tada! Enjoy your new root view controller without holding your day up with programmatic creation.
查看主应用程序委托 .m 文件并找到方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
里面会有这样一行
self .window.rootViewController = self.navigationController;
您可以在那里实例化不同的视图控制器并将其指定为 rootViewController
Look inside the main app delegate .m file and find the method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Inside it will be a line like this
self.window.rootViewController = self.navigationController;
You can instantiate a diffent view controller there and assign it to be the rootViewController