iOS - 从ViewController调用App Delegate方法 [英] iOS - Calling App Delegate method from ViewController

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

问题描述

我要做的是单击一个按钮(在代码中创建)并让它调用另一个视图控制器,然后让它在新的视图控制器中运行一个函数。

What I am trying to do is click a button (that was created in code) and have it call up a different view controller then have it run a function in the new view controller.

我知道它可以在IB中相对容易地完成,但这不是一个选项。

I know it could be done relatively easily in IB but that isn't an option.

我想要做的一个例子是if你有两个视图控制器,一个带有闪屏的房子。另一个视图控制器在房子上走过,你可以按照设定的顺序通过所有房间。启动画面会有每个房间的按钮,可以让你跳到步行的任何一点。

An example of what I want to do would be if you had two view controllers one with a splash screen of house. The other view controller had a walk through of the house on it that you could go through all the rooms in a set order. The splash screen would have buttons for each room that would allow you to jump to any point on the walk through.

推荐答案

你可以像这样访问委托:

You can access the delegate like this:

MainClass *appDelegate = (MainClass *)[[UIApplication sharedApplication] delegate];

MainClass 替换为您的应用程序类的名称。

Replace MainClass with the name of your application class.

然后,如果你有另一个视图控制器的属性,你可以调用类似的东西:

Then, provided you have a property for the other view controller, you can call something like:

[appDelegate.viewController someMethod];

这篇关于iOS - 从ViewController调用App Delegate方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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