0

I want to make an inspector window, like the inspector window of Preview mac application where I have a NSManagedObject model subclass and want to inspect it's properties

I've a main window, contains table of objects, and another window to show the properties of the selected object from the main window

my model is: (and it must be generic, the inspector must be able to inspect any NSManagedObject subclass instance, so the properties names aren't given)

@interface Metadata : NSManagedObject

@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * mail;

@end

the inspector window's table is intended to be like this:

 -------------------------------------------------
|type              name              value        |
|-------------------------------------------------|
|NSString            title             "sample"   |
|NSString            name              "sample"   |
|NSString            mail            "sample@mail"|
|_________________________________________________|

and of course changing in the inspector window will update values in the main window and vice versa

The problem is that I can't bind the inspector window to the model directly, because I want to bind to it's properties, so I have a model that have 3 properties to be viewed in a 3 rows table, each property in a row

if I create a new Class to hold the properties of the managed model, I'll lose the binding reference and may not even work

The problem is: I can't display the properties of a single (NSManagedObject subclass, in this case, Metadata) instance as a table, not only a columns, but a row for every property

AMTourky
  • 1,190
  • 13
  • 25
  • I do not understand your problem exactly: 1. Do you have a problem to synchronize the selection in the info window with the selected object in the main window or 2. do you have a problem to display the properties of a single instance as a table (NSArray)? – Amin Negm-Awad Dec 04 '13 at 22:29
  • yes, the second: I can't display the properties of a single (NSManagedObject subclass, in this case, Metadata) instance as a table – AMTourky Dec 05 '13 at 09:09
  • and of course I want the updates in the inspector to be sync with the main and vice versa – AMTourky Dec 05 '13 at 10:45

1 Answers1

0

The object that owns the main window (e.g., document) should have a property for the array of all objects and for an index set of the selected rows.

In your inspector, bind an array controller to those properties of the document:

  • content
    • Bind to: Document
    • Controller key: (should be disabled, IIRC)
    • Model key path: allObjects
  • selectionIndexes
    • Bind to: Document
    • Controller key: (should be disabled, IIRC)
    • Model key path: selectionIndexes

Remember that the model key paths identify the properties you're binding to, so if you call your two properties something different, you'll have to change the model key paths to match.

Then, bind your inspector's views through that array controller.

  • value
    • Bind to: Array controller
    • Controller key: selectedObjects
    • Model key path: title or name or mail

You could do the same to feed the table view: Have a separate array controller for the document, bound the same way, and bind the table columns' value bindings to metadata properties through the array controller.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • sorry for replying late, the problem is that I don't know the properties names, the inspector must be able to inspect any NSManagedObject subclass instance – AMTourky Dec 15 '13 at 15:07
  • Yes, I saw it before. But still how to connect all the pices tohether!? How to achieve the binding if the values need a run a code to get them!? – AMTourky Dec 15 '13 at 22:05
  • Actually I did it 'dirty implementation' using programatic binding, sending the message bind with key path, but its not good enough and I had to call it twice replacing the receiver each other – AMTourky Dec 15 '13 at 22:07
  • @AbdelhameedTourky: What do you mean by “the values need a run a code to get them”? The controller that owns the Inspector needs to examine the currently selected model object and gather all of its properties, creating a model object (with `propertyType`, `propertyName`, and `propertyValue` methods, including `setPropertyValue:` if you want that to be editable) to represent each one. You then bind an array controller to the Inspector controller's array of property objects, and the table view's columns to the various properties of the array controller's `arrangedObjects`. – Peter Hosey Dec 16 '13 at 01:15