在 MyViewController.h 中声明:
AppDelegate *appDelegate;
@property (nonatomic, strong) AppDelegate *appDelegate;
在 MyViewController.m 的 viewDidLoad 中:
self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
localAppDelegate= (AppDelegate *)[[UIApplication sharedApplication] delegate];
由于某种原因 appDelegate 保持为空,但 localAppDelegate 已正确分配。
为什么 self.appDelegate 没有被正确分配?