我要瘋了!我只是不明白。 當我開始第二個窗口時,在第二個窗口控制器中調用一個方法。該方法正在進行大量計算,並應通過網點將一些結果放入標籤中。標籤保持空白。我不知道如何使它工作。標籤不會標籤
我AppDelegate.m:
#import "AppDelegate.h"
#import "ToDoItem.h"
#import "ResultWindowController.h"
@implementation AppDelegate
- (IBAction)pushRun:(id)sender {
if (rwc)
{
[rwc close];
}
rwc = [[ResultWindowController alloc] init];
[rwc calculateResults];//add observer
[rwc setShouldCascadeWindows:NO]; //window re-opens at the same position
[rwc showWindow:self];
}
@end
我ResultWindowController.h:
#import <Cocoa/Cocoa.h>
@interface ResultWindowController : NSWindowController
{
}
@property (weak) IBOutlet NSTextField *outputResultAverageValue;
@property (weak) IBOutlet NSTextField *outputResultToleranceValue;
-(void)calculateResults;
@end
ResultWindowController.m:
-(void)awakeFromNib
{
NSString *initial [email protected]"-";
[_outputResultAverageValue setStringValue:initial];
[_outputResultToleranceValue setStringValue:initial];
}
- (void)calculateResults
{
double resultAverageValue = 0, resultToleranceValue = 0;
//calculations
for-loop{
resultAverageValue = (maxresult + minresult)/2;
resultToleranceValue = (maxresult - minresult)/2;
}
NSLog(@"resultaverage is:%f", resultAverageValue);
[_outputResultAverageValue setDoubleValue:resultAverageValue];
[_outputResultToleranceValue setDoubleValue:resultToleranceValue];
}
NSLog
給我我想要顯示我的價值標籤。我也可以使用awakeFromNib
方法初始化我的標籤。 我有設計失敗嗎?我需要確保在calculateResults
方法完成後設置標籤嗎?
在此先感謝!
'_outputResultAverageValue'的數據類型是什麼?代碼在哪裏試圖設置標籤的文本? – rmaddy
嗨rmaddy,我添加了上面的代碼。它總是需要成爲一個文本嗎? '_outputResultAverageValue'是連接到筆尖標籤的NSTextfield插座。 – JFS