0

I have an NSArrayController which handles entities of GeometryShape. GeometryShape has: name, type, color. LineShape is a GeometryShape and has: beginPositionX, beginPositionY, endPositionX, endPositionY. CircleShape is a GeometryShape and has: positionX, positionY, radius.

The NSTableView shows all inserted shapes in the NSArrayController, where each column is bound with arrangedObjects & the key name.

When I select a line shape, its properties are displayed in the Line tab - which is the default tab.

Now if I select a circle shape, I want the Circle tab to be selected and the circles properties to be displayed.

…and so depending on which shape type I select the corresponding tab will be selected and display the corresponding shape properties.

How may I achieve this excellent :) model?

enter image description here

NSGod
  • 22,699
  • 3
  • 58
  • 66
StackUnderflow
  • 2,403
  • 2
  • 21
  • 28

1 Answers1

0

I think you'd want to implement a NSTableViewDelegate and programmatically select the appropriate tab within an implementation of tableViewSelectionDidChange: When the selection changes, you just grab the tabView's IBOutlet and assign a new selectedIndex based on the arrayController's selection.

Alternately, you could bind the value of the tabView's selectedIndex to the array controller's selection, but you would need a custom value transformer that converted from the selection id to an NSUInteger that reflects the appropriate class.

In either implementation, you're writing code using isKindOfClass and mapping to an integer.

You may also be able to bind the tab view's selectedLabel to the array controller keypath of selection.class but I'm guessing you still would need a valuetransformer wrapping NSStringFromClass() as described in the NSValueTransformer docs. I'm not totally certain there's a completely non-code way of transforming the class to a string you could bind the selectedLabel to, though.

Personally, I don't love implementing the custom value transformer because you're writing code to allow implementing behavior buried in IB... all to avoid writing code that could live in a custom tableview delegate.

stevesliva
  • 5,351
  • 1
  • 16
  • 39