将数据从App委托传递到View Controller [英] Passing Data from App delegate to View Controller
本文介绍了将数据从App委托传递到View Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将一个字符串从App委托传递给我的初始视图控制器,
有人能列出我最好的方法吗,我也尝试使用NS用户默认值保存和检索,但我没有锻炼得当。
I need to Pass an string from App delegate to my Initial View Controller , Can somebody listed me the best way to do it , also i tried to Save and Retrieve using NS user Defaults, but i doesn't work out properly .
推荐答案
接口:
@interface MyAppDelegate : NSObject {
NSString *myString;
}
@property (nonatomic, retain) NSString *myString;
...
@end
和.m文件中的你会写的App Delegate:
and in the .m file for the App Delegate you would write:
@implementation MyAppDelegate
@synthesize myString;
myString = some string;
@end
然后,在viewcontroller.m文件中,您可以获取:
Then, in viewcontroller.m file you can fetch:
MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
someString = appDelegate.myString; //..to read
appDelegate.myString = some NSString; //..to write
这篇关于将数据从App委托传递到View Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文