Search code examples
objective-clabeloutlet

Labels won't label


I'm going crazy! I just don't get it. When I start a second window a method is called within the second window controller. The method is doing a lot of calculations and should put some results in labels via outlets. The labels remain empty. I don't know how to make it work.

my 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

my 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 =@"-";
    [_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 gives me the value I want to display in my Label. I also can initialize my labels using the awakeFromNib method. Do I have a design failure. Do I need to make sure that the labels are set after the calculateResults methode is done?

Thanks in advance!!!


Solution

  • I finally found my problem. I bound the outlets with the ResultWindowController object in the xib. I changed the binding to the File's Owner and it works now.