我想在我的視圖控制器中的多個方法中使用一個變量整數。 secondsLeft變量工作正常,但otherNumber變量不起作用。我得到的錯誤:初始化元素不是編譯時常量。任何想法,我應該如何做到這一點?謝謝!全局變量從應用程序代理拉
@interface ViewController()
@end
@implementation ViewController
@synthesize countDown,Timerlbl;
int secondsLeft = 500;
int otherNumber =[(AppDelegate *)[UIApplication sharedApplication].delegate otherNumber];
謝謝!相反,我正在使用@property方式。 – Brandon
如何獲取應用程序委託來注入值 - 此代碼是否在我的應用程序委託中? – Brandon
在你的應用程序委託中,當實例化你的'ViewController'時,像這樣'viewController = [[ViewController alloc] initWithSomeNumber:23849];'。你需要在'ViewController'的公共'@interface'中公開'initWithSomeNumber'' –