表格列上的复选框不会记录点击
我有一个表视图,可以动态添加列。必须以这种方式完成,因为我无法预测需要多少列或哪些列。
有些列是复选框,但在运行应用程序时无法单击它们。列和复选框设置为可编辑,但如果我单击复选框,则不会设置检查。我错过了什么吗?
更新
我如何(尝试)设置复选框的状态:
- (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);
*/
}
}
}
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);
*/
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的列是否绑定到控制器或者您是否使用 NSTableDataSource 协议?我怀疑是后者,但你需要具体说明。
按照我的假设:单击复选框的处理方式与
-tableView:setObjectValue:forTableColumn:row:
方法中的其他任何内容相同。您的对象将是按钮的状态......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 ...