0

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):

  1. the resultArray is bound as content to a NSArrayController via BindingInspector
  2. the NSArrayController is part of the result.xib
  3. the result.xib has a tableview (without own class or viewcontroller)
  4. the tableview columns are bound to the NSArrayController via keyvalues used in the resultArray

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.

JFS
  • 2,992
  • 3
  • 37
  • 48

1 Answers1

0

Instead of adding the object to your array, make an IBOutlet to your array controller, and use the method addObject: to add object's to your table view.

TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71
  • Hello TheAmateurProgrammer, do you mean I need to change `[resultArray addObject:newResult];` in `[resultArrayController addObject:newResult];` and create an outlet in `ResultWindowController`? – JFS Jan 18 '13 at 00:04