我要疯了!我只是不明白。 当我开始第二个窗口时,在第二个窗口控制器中调用一个方法。该方法正在进行大量计算,并应通过网点将一些结果放入标签中。标签保持空白。我不知道如何使它工作。标签不会标签
我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