Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
情况: 我正在使用“基于导航的应用程序”项目模板。而我的根视图控制器(UIViewController)需要调用应用委托的方法。
问题: 如何从 UIViewController 调用应用程序委托的方法?
[[[UIApplication sharedApplication] delegate] someMethod];
或者applicationDidFinishLaunching:设置一个由委托类的静态方法返回的静态成员。
applicationDidFinishLaunching:
+(id) shared { return sAppDelegate; } -(void) applicationDidFinishLaunching:(UIApplication *)a { sAppDelegate = self; }
或者只使用没有包装器的全局变量。