據我所知,NSViewController類的視圖必須加載之前,可以通過setter和getters在視圖中更改任何內容。問題是,控制器中的視圖應該顯示倒計時,所以視圖控制器類有一個NSTimer,它會每秒更改一次stringValue。但從我所看到的,我必須使用類似:可可:從NSViewController類中加載視圖
[instanceOfViewControllerClass view]
在另一個類中,以便視圖將加載,然後setStringValue
將工作。
我之前問過類似的問題,但答案是我上面所說的,當時我不知道我將不得不不斷改變視圖。
基本上就是我正在尋找的東西,是這樣的:
//ViewControllerClass.m
-(void)startCountdown{
//here I make "invocation" using NSInvocation
[invocation setTarget:self];
[invocation setSelector:@selector(updateCountdown)];
timerLabelUpdater = [NSTimer timerWithTimeInterval:1 invocation:invocation repeats:YES];
}
-(void)updateCountdown {
//x would be calculated here by deducting 1 from an original amount of time
[timeLeftLabel setStringValue:@"x"];
}
一切工作正常,如果我把一個NSLog的在它完美地記錄了updateCountdown,這意味着它運行時,我只是無法獲得標籤更改。
使用上面的答案我已經嘗試在上面的代碼中的幾個地方使用[self view]
和[self loadView]
,但它們都沒有區別。
我希望我已經明確了我要找的這一次,任何幫助將不勝感激。
什麼都沒有發生,我用 - (ID)initWithNibName:(的NSString *)nibNameOrNil束:(一個NSBundle *)nibBundleOrNil {自我= [ super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if(self){} return self;} 我認爲這並不完全相同。 – Elbimio 2011-12-25 18:03:16
您是否在代碼中創建視圖控制器?或者你是否在某個地方有一個筆尖?如果你有,如果在一個筆尖,你需要分配一個筆尖名稱。 – 2011-12-25 18:28:54
我剛剛添加了NSViewController類,在筆尖中沒有任何東西。 – Elbimio 2011-12-25 18:56:41