close

如果要在其他class存取 XXXAppDelegate內的變數有兩種做法

 

一.

1在XXXAppDelegate的變數設定@property

2在其他CLASS中 import XXXAppDelegate.h

3建立物件

   XXXAppDelegate=(XXXAppDelegate)[[UIApplication sharedApplication]delegate];

然後就可以存取其物件變數變數

 

二.

1.在XXXAppDelegate.h中建立+method

   +( XXXAppDelegate *)shareDelegate;

2.在XXXAppDelegate.h中實作

   +( XXXAppDelegate *)shareDelegate{

      return (XXXAppDelegate *)[[UIApplicationsharedApplication]delegate];

   }

3.在其他CLASS中import XXXAppDelegate.h

   [SuperSalerAppDelegateshareDelegate] 就可當物件直接存取,因為method是+,所以該物件不用初始化

arrow
arrow
    全站熱搜

    zer931 發表在 痞客邦 留言(0) 人氣()