读书人

AppDelegate 回调用法解决方案

发布时间: 2014-01-22 00:03:39 作者: rapoo

AppDelegate 回调用法
程序幼儿员求教:
请问在 #import "RootViewController.h" 的 - (void)viewDidLoad 里面执行了下面一行代码 后 AppDelegate 做了什么

[([UIApplication sharedApplication].delegate) performSelector:@selector(login)];

[解决办法]
如果[UIApplication sharedApplication].delegate是appDelegate的话,那么他执行了login方法
正常情况下(系统默认)[UIApplication sharedApplication].delegate就是AppDelegate,当然你可以到main.m文件中修改他
[解决办法]
[UIApplication sharedApplication].delegate 中的delegate 的定义

@property (nonatomic,assign) id <UIApplicationDelegate> delegate;

所以在调用[UIApplication sharedApplication].delegate时表示了,要调用实现了UIApplicationDelegate协议的类。而我们知道,在App中,只有AppDelegate.h 类实现了UIApplicationDelegate 协议,那么你上面的代码
 [([UIApplication sharedApplication].delegate) performSelector:@selector(login)];

则表示调用实现了UIApplicationDelegate协议的类的方法login

读书人网 >Iphone

热点推荐