NSButtonCell as Checkbox in a NSTableVIew don't get selected

微笑、不失礼 提交于 2019-12-07 06:09:04

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4313490/nsbuttoncell-as-checkbox-in-a-nstableview-dont-get-selected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!