如何从非 ViewController 助手类显示 ViewController? [英] How to show ViewController from a non-ViewController helper class?

查看:49
本文介绍了如何从非 ViewController 助手类显示 ViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我们从某个 UIViewController 对象调用 self.presentViewController(...),但是如何从一个不是 UIViewController 的辅助类中的类类型(静态)函数显示一个新的视图控制器.

Usually we call self.presentViewController(...) from some UIViewController object, but how to show a new view controller from a class type (static) function in a helper class which is not a UIViewController.

推荐答案

您可以将 helper 类中的 viewController 显示为 navigationcontroller 的根视图控制器

You can show your viewController from helper class as root view controller of navigationcontroller

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];

UINavigationController *controller = (UINavigationController*)[storyBoard
                                                               instantiateViewControllerWithIdentifier: @"RootNavigationController"]; //set storyboard ID to your root navigationController.

YourViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"YourViewController"]; // //set storyboard ID to viewController.
[controller setViewControllers:[NSArray arrayWithObject:vc] animated:YES];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController=controller;

这篇关于如何从非 ViewController 助手类显示 ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆