SMGreenfield
SMGreenfield

Reputation: 1720

Should an NSTableView's NSTableViewDataSource and NSTableViewDelegate be in a separate NSViewController from controller for rest of NSView?

I have an NSView, "CurrentActionsView", that contains buttons, text and a NSTableView. A class, CurrentActionsViewController, which is an NSViewController, handles the initialization of all the controls -- except for the NSTableView ("myTableView"), which has its own custom class object in the .xib ("myTableViewController"). That maps to a class which is simply:

@interface ActivationTableController : NSObject <NSTableViewDataSource, NSTableViewDelegate>

My question is this:

Should I just add NSTableViewDataSource and NSTableViewDelegate to the CurrentActionsViewController class, which is already an NSViewController, so there is only one controller responsible for handling all the objects in the CurrentActionsView?

Because I presently have these two separate controllers in two separate files, it's a complex path for the CurrentActionsView to reach into myTableViewController when it needs to re-initialize and reload data in the table.

Upvotes: 0

Views: 356

Answers (1)

Aaron
Aaron

Reputation: 889

I usually start by just having the view controller serve as the table view's delegate and data source; it's not a bad starting point.

As your app gets more complex you might find that your view controller's getting too many responsibilities and you might want to extract out an object that specifically deals with the NSTableView.

If you do set up your view controller as a table view delegate and data source just be careful not to too tightly couple your table view-related code to the rest of the view controller; at that point it might become difficult to extract it out.

Upvotes: 1

Related Questions