表列上的复选框不会注册点击 [英] Checkbox on table column won't register click
问题描述
我有一个动态添加列的表视图。它必须这样做,因为我不能预测需要多少或哪些列。
某些列是复选框,但我可以当我运行我的应用程序时点击他们。列和复选框设置为可编辑,但如果我单击复选框,将不会设置检查。
我是(尝试)设置状态的复选框:
- (void)tableView:(NSTableView *)theTableView
setObjectValue: )theObject
forTableColumn:(NSTableColumn *)thecolumn
row:(int)rowIndex
{
if(theTableView == resultsTableView){
if [[列的标识符] isEqualToString:CHCheckBoxColumnIdentifier]){
NSInteger state = [[theColumn dataCell] state];
if(state == NSOnState){
[[TheColumn dataCell] setState:NSOffState];
} else {
[[TheColumn dataCell] setState:NSOnState];
}
/ *
NSLog(@%@,theObject);
NSLog(@%@,theColumn);
NSLog(@%i,rowIndex);
* /
}
}
}
您的列是绑定到控制器还是使用NSTableDataSource协议?我怀疑后者,但你需要指定。
继续我的假设:点击复选框的处理方式与 -tableView:setObjectValue:forTableColumn:row:
方法。你的对象将是按钮的状态...
I've a table view to which I add columns dynamically. It must be done this way because I can't predict how many or which columns I will need.
Some columns are checkboxes but I can't click on them when I run my application. The column and checkbox are set to be editable but if I click on the checkbox the check won't get set. Am I missing something?
Update
How I'm (trying) setting the state on the checkbox:
- (void)tableView:(NSTableView *)theTableView
setObjectValue:(id)theObject
forTableColumn:(NSTableColumn *)theColumn
row:(int)rowIndex
{
if (theTableView == resultsTableView) {
if ([[theColumn identifier] isEqualToString:CHCheckBoxColumnIdentifier]) {
NSInteger state = [[theColumn dataCell] state];
if (state == NSOnState) {
[[theColumn dataCell] setState:NSOffState];
} else {
[[theColumn dataCell] setState:NSOnState];
}
/*
NSLog(@"%@", theObject);
NSLog(@"%@", theColumn);
NSLog(@"%i", rowIndex);
*/
}
}
}
Are your columns bound to a controller or are you using the NSTableDataSource protocol? I suspect the latter but you'll need to specify.
Going on my assumption: a click on a checkbox is handled the same way as anything else in the -tableView:setObjectValue:forTableColumn:row:
method. Your object will be the state of the button ...
这篇关于表列上的复选框不会注册点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!