NSButtonCell as Checkbox in a NSTableVIew don't get selected
Asked Answered
F

1

5

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?

Fibriform answered 30/11, 2010 at 12:2 Comment(1)
There's not much to go by here. How are you feeding the NSTableView data?Stuartstub
N
11

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.

Nubbly answered 11/2, 2011 at 22:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.