XIB Designer, is it possible to bind NSTableView to DataSource from different unit then main unit?

The NSTableView requires a data source to work. In the examples the data source is usually implemented as addion to the main window controller.

With XCode it is (apparently) possible to define a NSTableViewDataSource in a different unit and to be still able to bind it visually in the designer.

Yesterday I was trying different things out, without success. In the end
I just added one line of code and it works great - with no visual binding.

 method MainWindowController.awakeFromNib;
 begin
    inherited;
    adressTableView.dataSource := controllerForAdressTable;
end;

The controller is implemented in a different unit and an instance is created in the window object:

 ControllerForAddressData = public class( INSTableViewDataSource)
 public
    myData : NSMutableArray;
    method tableView(tblView : NSTableView) objectValueForTableColumn(tableColumn: NSTableColumn) row(row : NSInteger): id;
    method tableView(tblView : NSTableView) setObjectValue(obj: id) forTableColumn(tableColumn : NSTableColumn) row(row: NSInteger);
    method numberOfRowsInTableView(tblView : NSTableView): NSInteger;
    constructor ;
end;

My question:
Is it possible to use visual binding in such a case - if not, that info is imho missing in the “Using XIB storybook” wiki chapter. My solution is easy enough, but it took quite some time of trials and errors to find since the XCode books use the visual drag&drop approach.

Regards,
Julian

Should be possible. Just make sure your extra class is marked as [IBObject] and it should show in Interface Builder.

I thought so, too. But when I have this code:

[IBObject]
 SomeDataController = public class( INSTableViewDataSource)
 public
...

I do not find it anywhere in the designer. As mentioned, I fixed it for me by runtime assignment.

In XCode when I edit the XIB created by Elements I do not see the source files as I would, when I would just use XCode. I just see FileOwner which is the window main class in the main unit. This is all no severe problem right now, but I think it will bite some time, when I try to do something more fancy, like using the CoreData functions for example.
It would help if it is documented what is done when the source is “synchronized to XCode” to understand the concept better.

Another thing I wonder: When I do a Save (Command S) in XCode, Elements will not pick up the change automatically. I have to do a BuildAll. I also miss a function to launch XCode from the Elements IDE directly with the correct file loaded - through CrossBox this should be possible. (For some reason XCode does not even list the project under “Recent”)

I also found some things which may be helpful to other beginners like me:

  1. In the XCode project the flag “Use Auto Layout” under Document editing should be off. Otherwise it is not possible to set Anchors and alignment to controls.
  2. Sometimes after a change in the designer this error pops up in Elements: “Error 5 (ProcessXibs) An exception occurred on the server: Execution of “ibtool” failed with error code 1
    This error is caused by an incompatible setting in the XIB. To easily find the problem click in XCode on the alert symbol in the top left area and it will show you whats wrong.

Regards,
Julian