Redraw NSTableView with new data from file when NSViewController re-loaded?

820 views Asked by At

I have a Mac OS X Document based app that has multiple NSViewControllers that I switch between and each view displays data from plist files in NSTableViews based on the user selections in the previous NSViewController's NSTableView. The problem I have is that I can't figure out what function can be called, every time a NSViewController gets loaded, to read the correct data from a file to display in the NSTableView. For UIViewControllers I used the function family of viewDidLoad, viewWillAppear, but I haven't been able to find the corresponding functions for NSViewController.

Currently I am using awakeFromNib, which works fine, but only the first time the NSViewController gets loaded. I've tried loadView, but that collapses the NSView. I assume that I need to do more setup to use loadView.

I'm using the View Swapping code from Hillegass's book Cocoa Programming for MAC OS X which switches ViewControllers with the following code:

  - (void)displayViewController:(ManagingViewController *)vc
                   curBox: (NSBox *)windowBox

  {
// End editing
NSWindow *w = [windowBox window];
BOOL ended = [w makeFirstResponder:w];
if (!ended) {
    NSBeep();
    return;
}
NSView *v = [vc view];

NSSize currentSize = [[windowBox contentView] frame].size;

NSSize newSize = [v frame].size;

float deltaWidth  = newSize.width  - currentSize.width;
float deltaHeight = newSize.height - currentSize.height;

NSRect windowFrame = [w frame];
windowFrame.size.height += deltaHeight;
windowFrame.origin.y -= deltaHeight;
windowFrame.size.width += deltaWidth;

[windowBox setContentView:nil];
[w setFrame:windowFrame
    display:YES
    animate:YES];

[windowBox setContentView:v];

// Put the view controller in the responder chain

[v setNextResponder:vc];
[vc setNextResponder:windowBox];
 }

and puts the NSView Controller in the responder chain.

Is there some function I can call to setup the view every time I swap NSViewControllers? Can I check that a NSViewController has become the firstResponder?

1

There are 1 answers

0
James Testa On BEST ANSWER

This post provided the answer.

I added the following code:

- (void)viewWillLoad {

}

- (void)viewDidLoad {

}

- (void)loadView {
[self viewWillLoad];
[super loadView];
[self viewDidLoad];
}

and at the beginning of displayViewController I added

[vc loadView]