NSButtonCell作为复选框在NSTableVIew不选择 [英] NSButtonCell as Checkbox in a NSTableVIew don't get selected

查看:517
本文介绍了NSButtonCell作为复选框在NSTableVIew不选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSTableVIew用于多选择用两列,第一个用NSButtonCell作为复选框,另一个作为标题。





问题是当我点击它们时,复选框不会改变它的状态。我试图附加一个IBAction,但发件人的行动是TableView,但不是复选框



关于如何实现这种功能的任何想法(或链接) ?

解决方案

继续使用 NSTableViewDataSource 需要实现三个方法:

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

当单击复选框时,调用第一个方法。如果aTableColumn有你的复选框,你将保存新的状态,这是 [anObject boolValue]



需要绘制一行,它调用第二个方法。当表列为您的checkbox列时,返回您在第一个方法中保存的状态。



最后一个方法告诉表视图将有多少行。 / p>

请参阅表数据源文档了解更多细节,但我在这里大致总结了它。


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?

解决方案

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.

这篇关于NSButtonCell作为复选框在NSTableVIew不选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆