获取复选框以在NSTableColumn中反映其状态
我正在制作这个程序,它有一个带有四列的NSTableView,其中两列是复选框。我现在只想让一个人工作而且我已经卡住了。
首先,这是我的相关代码:
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
NSString *filePathThree = [[NSBundle mainBundle] pathForResource:@"mydictionary" ofType:@"plist"];
NSData *myDataThree = [[NSData alloc]initWithContentsOfFile:filePathThree];
self.flozzCodeAndName = (NSMutableDictionary *)[NSPropertyListSerialization
propertyListFromData:myDataThree
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:NULL
errorDescription:NULL];
return [[flozzCodeAndName objectForKey:@"name"] count];
}
- (void)tableView:(NSTableView *)tableView
setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
NSButtonCell *cell;
cell = [[NSButtonCell alloc] init];
[cell setButtonType:NSSwitchButton];
[cell setTitle:@""];
[cell setTag:rowIndex];
NSLog(@"%d", [cell tag]);
[cell setCellAttribute:NSCellEditable to:3];
[cell setImagePosition:NSImageOnly];
[cell setState:NSOnState];
NSLog(@"%d", [cell state]);
[havzColumn setDataCell:cell];
[myTableVeew reloadData];
[cell release];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
NSString *filePathThree = [[NSBundle mainBundle] pathForResource:@"mydictionary" ofType:@"plist"];
NSData *myDataThree = [[NSData alloc]initWithContentsOfFile:filePathThree];
self.flozzCodeAndName = (NSMutableDictionary *)[NSPropertyListSerialization
propertyListFromData:myDataThree
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:NULL
errorDescription:NULL];
NSArray *myArray = [flozzCodeAndName objectForKey:[aTableColumn identifier]];
NSString *myStringValue = [myArray objectAtIndex:rowIndex];
return myStringValue;
}
如您所见,我正在使用此表的数据源方法而不是绑定。我为Cocoa阅读的书中有一些带有标签的复选框,但我认为它们是一个数组,所以这可能不是最好的事情。
无论如何,当我运行它时,调试器将向我显示标签(等于行)以及按钮的状态(由于NSOnState,所有这些都为1)。我的问题是,根据他们的状态,我无法检查和取消选中框。我读到了这个问题:表格栏上的复选框不会注册点击
然后是NSTableView数据源参考。根据链接问题中的Nozzi先生的说法,在我看来,需要一个包含盒子状态的数组,所以我尝试了,将[cell state]
设置为NSNumber以使其进入NSMutableArray。我很满意,不认为那是对的。对于所有四列,此表中有454行(标签转到453,因为数组从0开始)。
我也想知道是否应该将tableview中的单元定义内容:setObjectValue:放入'awakeFromNib'中。我确实在IB中放了一个复选框按钮单元,但我之前遇到了问题,所以我决定以编程方式进行。在所有这些过程中,我做了,现在仍然在setObjectValue方法中有一个[myTableVeew reloadData]
。
我们非常感谢您的帮助,如果需要任何其他信息,我可以得到它。
没有找到相关结果
已邀请:
1 个回复
究补闯