NSButtonCell as a flag in NSTableVIew is not selected

I have NSTableVIew for multi-user purposes with two columns, the first with the NSButtonCell flag, and the other as the header.

The idea is to check the elements to be added after the words to the array.

The problem is that the checkboxes do not change their state when I click on them. I tried to enable IBAction, but the sender for the action is a TableView, but not a checkbox

Any ideas (or links) on how to achieve such functionality?

+4
source share
1 answer

Assuming you are using an 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 you click on the flag, the first method is called. If aTableColumn has your checkboxes, you will save a new state, which is [anObject boolValue] .

When a 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 how many rows there will be.

See the table data source documentation for more details, but I gave it briefly here.

+9
source

Source: https://habr.com/ru/post/897399/


All Articles