当前位置: 代码迷 >> Iphone >> AppDelegate 回调用法,该怎么解决
  详细解决方案

AppDelegate 回调用法,该怎么解决

热度:112   发布时间:2016-04-25 05:52:35.0
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