0
votes

A TableView is created in IB, and it is desired that it have only one column with checkboxes. One way to create the checkboxes is to drag an NSButtonCell into the column using IB, and then conforming to the NSTableViewDataSource protocol implement:

- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView

Hence when a class object is acting as a datasource to a column in a TableView, and the column contains objects such as checkboxes for each row, is the class supplying the only the on/off state data for the checkboxes, or is it also supplying the checkbox objects?

Related questions are:

  1. Is the TableView creating and containing the NSButtonCells?
  2. If the answer to 1 is yes, how can one set/change the NSButtonCell's properties, like its title?
  3. Rather than the TableView creating and maintaining the NSButtonCells, can the datasource class create them? That is, instead of using IB to drag the NSButtonCell to the column, can one add the NSButtonCells in a method such as awakeFromNIB?
  4. Is there a way to mix the types of cell objects in a given column. For example, could one have a text heading in column1row1 followed by a checkbox in column1row2?

Thanks.

1

1 Answers

0
votes

I think you are finding it difficult to understand the difference between Model,View and the Controller.

Your Class object should only act as "Model" - in your case supply the on/off state data. Your IB provides the "View" part ,Normally you should use it for creating any user interface. Your View Controller class which impliments tableview delegate/datsource methods is the"Controller" part and you should use it as a mediator between View and Model.

You can choose to provide button state along with title in your Model. and can set it in your Controllers implementation of the delegate/datasource method.

Yes, you can create button cells in your controller but avoid it unless it is absolutely necessary.

You can mix different types of cells,Instead you can choose to look into the View based TableView also.