0
如何組織訪問屬性MyAppDelegate對象MyClass(例如:MyViewController)。我可以從MyAppDelegate目錄中獲取它,或者我應該將它作爲參數或其他參數傳遞給init方法?訪問AppDelegate對象屬性
如何組織訪問屬性MyAppDelegate對象MyClass(例如:MyViewController)。我可以從MyAppDelegate目錄中獲取它,或者我應該將它作爲參數或其他參數傳遞給init方法?訪問AppDelegate對象屬性
這取決於你想做什麼......傳遞對其他類有用的對象是一個好主意。但是,如果你真的想訪問你的AppDelegate財產之一,定義(爲方便起見):
#define MY_APPDELEGATE ((YourAppDelegate*)[UIApplication sharedApplication].delegate)
然後訪問你的財產是這樣的:
MY_APPDELEGATE.myproperty
謝謝你。 – GeneCode
請重新表述您的問題,它不是真正清楚,我你想完成什麼。 –