Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSButtonCell as Checkbox in a NSTableVIew don't get selected

I have a NSTableVIew for multi-selection purposes with two columns, the first one with a NSButtonCell as checkbox and the other one as a title.

The idea is to check the items to be added afterwords to an array.

The problem is that the checkboxes don't change its state when I click them. I've tried to attach an IBAction but the sender to de action is the TableView but not the checkbox

Any ideas (or link) about how to achieve this kind of functionality?

like image 216
Omer Avatar asked Nov 30 '10 12:11

Omer


1 Answers

Going on the assumption you're using a NSTableViewDataSource you need to implement three methods:

- (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

When the checkbox is clicked the first method is called. If aTableColumn has your checkboxes you would save the new state, which is [anObject boolValue].

When the table needs to draw a row, it calls the second method. When the table column is your checkbox column, return the state that you saved in the first method.

The last method tells the table view how many rows there will be.

See the table data source documentation for more details, but I've pretty much summarized it here.

like image 154
Scott K. Avatar answered Oct 13 '22 22:10

Scott K.