I'm trying to figure out how to reload data in NSViewController.
I have a project like this, left side bar is NSOutlineView (which controlled by my outlineViewController) and the right split view is a custom view:
So I have this "profile.xib" file, which contains some information of the "person"'s object. I have set the profile.xib file owner to my view controller, ProfileViewController, which is a subclass of NSViewController.
So, each time when user selects a different profile from the side bar, my outlineviewController will call:
if (!_profileViewController)
_profileViewController = [[ProfileViewController alloc] initWithNibName:@"profile" bundle:nil];
[_profileViewController setProfile: item]; //item is an instance of the profile object
NSView *view = [_profileViewController view];
view.frame = _mainContentView.bounds;
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[_mainContentView addSubview:view]; //add profile's view to the right hand side split view
(code is taken from the sidebardemo from apple)
Since user may select different profile from the sidebar, I need to reload the data in my ProfileViewController. However I can't figure which method should contains my reload data code. If I put my "reload data code" in awakefromnib, it will be called once, also viewload will only call once. I don't want to reallocate and reinitialize _profileViewController everything when profile is selected, due to the memory concern.
I can't use binding here, as some of the fields are quite complex to display.
so how am I going to reload the data?
How about moving your "load the profile information into the view" code from -awakeFromNib into its own -reloadData method and calling that when -setProfile: is called? You do this either by calling it yourself from the table view or by overriding -setProfile: to note the profile then call -reloadData immediately thereafter.