[英]Push to a UIViewController from inside of NSObject's subclass
I am a newbie in Objective-C. 我是Objective-C的新手。 I stucked into a very big problem.
我陷入了一个很大的问题。
I have a ModelClass (named MyModel) for data management which is a subclass of NSObject... And to access the data the app needs authentication using a viewcontroller (say X) I don't have access to its properties (Actually it is a framework's viewcontroller)... I am accessing that model class from a viewController (named MyViewController)..and I want the retrieval along with authentication of data by calling one method of that model class...but, to present the uncontrolable viewcontroller X for authentication; 我有一个用于数据管理的ModelClass(名为MyModel),它是NSObject的子类...并且要访问数据,应用需要使用ViewController进行身份验证(例如X),但我无法访问其属性(实际上是框架的viewcontroller)...我正在从viewController(名为MyViewController)访问该模型类。.我希望通过调用该模型类的一个方法来进行数据的身份验证和检索...但是,提出无法控制的viewcontroller X用于身份验证; I must use pushToViewController: method of UINavigationController SDK class.
我必须使用UINavigationController SDK类的pushToViewController:方法。 And I found that subclasses of NSObject class do not respond to navigationController.
而且我发现NSObject类的子类不响应navigationController。
But I really need to do this. 但是我确实需要这样做。 Any kind of effective help is appreciated and thanks in advance.
任何有效的帮助,我们都表示赞赏和感谢。
I've found a way to do this. 我找到了一种方法。 I am giving the steps-
我正在采取步骤-
1> Create an UIViewController property (say obj) in MyModel. 1>在MyModel中创建一个UIViewController属性(例如obj)。
2> Assign that obj to self(MyViewController's self object) just after creating the object of the model class(MyModel). 2>在创建模型类(MyModel)的对象之后,将该obj分配给self(MyViewController的self对象)。
3> Put the following line in the model class from where to push to the target viewcontroller (for mine X)- 3>将以下行放入模型类中,从此处推送到目标ViewController(对于我的X)-
[self.obj pushViewcontroller:targetViewController animated:YES];
That's it. 而已。 And thanks all.
谢谢大家
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.