我有一个包含所有数据的 NSDictionary:
- 一个标题(对这个问题不重要)
- 一个链接(对这个问题不重要)
- 一组 NSDictionary 再次包含 1 个标题和 1 个链接
我在基于视图的表视图中显示这些数据,如下所示:
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tv
{
    if (tv == _downloadTable) 
    //I use this "if" because I have another tableView that has nothing to do
    //with this one
    {
        return [[myDictionary objectForKey:@"myArray"] count];
    }
}
我想要 2 列tableView,一列显示标题,一列带有复选框,这可以让我知道检查了哪一行。
- (NSView *)tableView:(NSTableView *)tv viewForTableColumn :(NSTableColumn *)tableColumn row :(NSInteger)row 
{
    if (tv == _downloadTable) 
    {
        if (tableColumn == _downloadTableTitleColumn) 
        {
            if ([[[myDictionary         objectForKey:@"myArray"]objectAtIndex:row]objectForKey:@"title"]) 
            {
            NSString *title = [[[myDictionary objectForKey:@"myArray"]objectAtIndex:row]objectForKey:@"title"];
            NSTableCellView *result = [tv makeViewWithIdentifier:tableColumn.identifier owner:self];
            result.textField.stringValue = title;
            return result;
            }
        }
       if (tableColumn == _downloadTableCheckColumn) 
       {
           NSLog(@"CheckBox"); //I wanted to see exactly when that was called
                               //But it didn't help me :(
           NSButton *button = [[NSButton alloc]init];
           [button setButtonType:NSSwitchButton];
           [button setTitle:@""];
           return button;
       }
   }
}
现在,当我运行它并单击复选框时,它什么也不做(当然,因为我不知道如何让它做某事。我应该把应该做某事的代码放在哪里?
主要目标是一个可编辑的下载列表,现在显示列表,每行标题旁边都有复选框。我想知道哪些复选框被选中,哪些没有。
我试过这个:
[button setAction:@selector(checkBoxAction:)];
- (void)checkBoxAction: (id)sender
{
   NSLog(@"I am button : %@ and my state is %ld", sender, (long)[sender state]);
}
但我不知道如何获取该按钮的行,以了解与此复选框相关联的标题。
我也尝试了没有成功的setObjectValue方法。tableView
我希望它的工作方式是:
我有一个“开始下载”按钮,用于检查每个复选框是否被选中,并仅在选中的行中启动下一个操作(下载)。
我想避免绑定,因为我也打算让它在 iOS 上工作,而且我不想为 iOS 使用不同的代码。