How to pass data from AppDelegate to ViewController?

陌路散爱 提交于 2019-12-06 08:38:34

This is just a few line of code, required to accomplish it.

Put this line in appDelegate.h file

First of all you need to conforms to a protocol as follow

@interface AppDelegate : UIResponder <UIApplicationDelegate>

Now need to declare one property for it to use as follow

@property (strong, nonatomic) id<UIApplicationDelegate>delagete;

Now the last and final stage to use the property in view controller is as follow

In .h file of viewcontroller
First put reference to appdelegate like this #import "AppDelegate.h"
Then one iVar as AppDelegate *appDel; in @interface

Now in .m file
put appDel = [[UIApplication sharedApplication]delegate]; in view did load method and access the appdelegate's all property there like appDel.paramArray.

Happy Coding :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!