gpt4 book ai didi

objective-c - 如何使用 Cocoa Bindings 将复选框单元添加到 NSTableView?

转载 作者:行者123 更新时间:2023-12-03 16:38:32 25 4
gpt4 key购买 nike

我是 cocoa 的新手。我有一个存储联系人的表。我没有使用 NSTableView 协议(protocol)。我正在使用 Cocoa Bindings 和 Mutable Array 来存储在其中。问题是,我希望能够在每一行上都有复选框,然后选择我想要的联系人,并且能够获取选定的行。我该怎么做?当我尝试将复选框单元格放入表列时,没有任何效果。这是我的代码,我如何填充我的 NSTableView 联系人。那么应该怎么做才能添加复选框并处理它们呢?谢谢。

  NSMutableDictionary *dict =[NSMutableDictionary dictionaryWithObjectsAndKeys:
Name, @"Name",
Surname, @"Surname",
Education,@"Education",
nil];

//controller for binding data to NSTableView
[controllerContacts addObject:dict];
//Table for viewing data.
[viewTableOfContacts reloadData];

最佳答案

如果你想通过绑定(bind)在每一行使用复选框,你需要在字典中定义一个与你的复选框绑定(bind)相对应的键。

就你而言,它可以是这样的-

  NSMutableDictionary *dict =[NSMutableDictionary dictionaryWithObjectsAndKeys:
Name, @"Name",
Surname, @"Surname",
Education,@"Education",
[NSNumber numberWithInt:0],@"selectedStudent",
nil];

然后将该列绑定(bind)为“selectedStudent”键。

此外,如果您只想检索选定的行,您可以像这样使用 NSPredicate -

NSPredicate *selectedStudentPredicate = [NSPredicate predicateWithFormat:@"selectedStudent == 1"];
NSArray *selectedStudents = [controllerContacts filteredArrayUsingPredicate:selectedStudentPredicate];

希望这有帮助!

关于objective-c - 如何使用 Cocoa Bindings 将复选框单元添加到 NSTableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7546315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com