Mutliple views for detail in a master-detail interface
I am building a preferences pane for an app where the user can add a Web Service to a list (in a tableview on the left) and a form should appear on the right where the user can edit configuration options for the web service (like username or password or API key or tumblr blog name, etc.) I think I'll need different views for different types of service (possibly with different logic for validation and so on).
My question is what is the best way to implement this?
What I've done: I have a NSSplitView
with a NSTableView
. I have an NSArrayController
with it's content
bound to the appropriate key in NSUserDefaultsController
and the NSTableView
bound to it's arrangedObjects
and selectionIndexes
. Next I've added a NSTabView
in the right with it's selectedIndex
bound to the NSArrayController
's selectedIndex and I'm trying to programatically insert the appropriate views (which I've created as separate custom views in IB) as tabs.
This seems to me to be a not the best approach. I also don't know what to bind the fields in the detail views - is it even possible to use bindings 开发者_如何学运维here? How would you solve this problem?
Instead of the NSTabView
, create a blank NSView
for the inspector (inspectorView
). Same idea, but a little simpler.
In tableViewSelectionDidChange
, write something like:
newView = ...;
if (inspectorView != [customInspectorView superview]) {
NSView *oldView = [[inspectorView subviews] objectAtIndex:0];
[inspectorView replaceSubview:oldView with:newView];
}
You can bind your fields to servicesArrayController.selection.username
and so on.
精彩评论