I have another simple question I can not solve by myself. I have two xibs. main.xib for the user input and result.xib for the results. Xib2 starts when a button is pushed on input-xib. The button action (in AppDelegate.m):
- (IBAction)pushRun:(id)sender {
if (!rwc)
{
rwc = [[ResultWindowController alloc] init];
}
[rwc setValueArray:[toDoItemArrayController arrangedObjects]];
[rwc setNumberOfCalculations:[NSNumber numberWithInt:[_inputNumberOfCalculations intValue]]];
[rwc calculateResults]; //starts method in 2nd-window controller for result calculation
[rwc showWindow:self];
}
rwc
is a WindowController
doing the calculation and showing the result.xib (ResultWindow
):
ResultWindowController.h:
#import <Cocoa/Cocoa.h>
@interface ResultWindowController : NSWindowController{
NSArray *valueArray;
NSMutableArray *resultArray;
NSNumber *numberOfCalculations;
}
@property (nonatomic, retain, readwrite) NSArray *valueArray;
@property (retain) NSNumber *numberOfCalculations;
@property (nonatomic, retain, readwrite) NSMutableArray *resultArray;
-(void)calculateResults;
@end
ResultWindowController.m:
#import "ResultWindowController.h"
#import "ResultItem.h" //my result model
@implementation ResultWindowController
@synthesize valueArray, resultArray, numberOfCalculations;
- (id)init
{
if(![super initWithWindowNibName:@"ResultWindow"])
return nil;
return self;
}
-(void)awakeFromNib
{
}
- (void)windowDidLoad
{
[super windowDidLoad];
}
- (void)calculateResults
{
//a lot of calculation code ...
ResultItem *newResult = [[ResultItem alloc]init];
[newResult setValue:[nameArray objectAtIndex:i] forKey:@"name"];
[newResult setValue:[NSNumber numberWithDouble:avg] forKey:@"averageValue"];
[newResult setValue:[NSNumber numberWithDouble:min] forKey:@"minValue"];
[newResult setValue:[NSNumber numberWithDouble:max] forKey:@"maxValue"];
[newResult setValue:dimensionRandomArray forKey:@"randomArray"];
[resultArray addObject:newResult];
}
The results are put in an model-object and collected in the resultArray
.
Now it's going to get interesting (at least for me):
- the
resultArray
is bound as content to aNSArrayController
via BindingInspector - the
NSArrayController
is part of the result.xib - the result.xib has a
tableview
(without own class or viewcontroller) - the
tableview
columns are bound to theNSArrayController
via keyvalues used in theresultArray
Everything works really fine when the result.xib window starts. The tableview
shows the content as expected. BUT! When I make changes at the input.xib and push the action button again the tableview
at the result.xib is not updating.
I checked the resultArray
content (via NSLog) and it gets all the new values, so works fine.
WHERE IS MY PROBLEM?
I read a lot of [tableView reloadData]
but I don't know how to actuallay set up the code and the necessary bindings for it.