Call a function in AppDelegate?

前端 未结 4 652
暖寄归人
暖寄归人 2020-12-19 13:14

Following the solution (the highest-voted answer actually) at UITextField Example in Cocos2d, I managed to do it except the line

[[[UIApplication sharedAppli         


        
4条回答
  •  梦毁少年i
    2020-12-19 14:09

    You need to import the AppDelegate into the .m file where you use

    [[[UIApplication sharedApplication] delegate] specifyStartLevel];
    

    I like to import it with a header that gives me a shortcut.

    GlobalData.h
    
    #import "AppDelegate.h"
    #define APPDELEGATE (AppDelegate *)[[UIApplication sharedApplication] delegate]
    

    Then when I use it in any class I just

    #import "GlobalData.h"
    
    // to gain access to the delegate
    AppDelegate * appDelegate = APPDELEGATE;
    

    I use this approach because I can then store more #define's to some global constants (ie soundFXVolume - #define SOUND_FX_V 0.6)

提交回复
热议问题