从NSObject类调用presentModalViewController [英] Call presentModalViewController from NSObject class

查看:229
本文介绍了从NSObject类调用presentModalViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的子类 NSObject 我想调用

    [[self navController] presentModalViewController:myView animated:YES];

但我的尝试都没有成功。如果我不在 UIViewController

But none of my tries were successful. How can I call a modal view if I'm not in a subclass of UIViewController?

解决方案:

#import "myProjectNameAppDelegate.h"
// ...
MyViewController *myView = [[MyViewController alloc] init];
myProjectNameAppDelegate *appDelegate = (myProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
[[appDelegate navController] presentModalViewController:myView animated:YES];


推荐答案

我看不到显示模态视图没有ViewController。你必须在类中存储对UIViewController的引用,所以你可以访问它。或者在您的AppDelegate中设置一个属性,您可以通过调用[[UIApplication sharedApplication] delegate];

I don't see a way to display a modal view without a ViewController. You have to store a reference to a UIViewController in your class so you can access it. Or setup a property in your AppDelegate, which you can get by calling [[UIApplication sharedApplication] delegate];

这篇关于从NSObject类调用presentModalViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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