0

::edit - 已解决.. 我没有正确遵守 NSComboBoxDataSource ..

我有一个可以工作的 NSComboBox 实现 - 除了 - 当数据源发生更改时,在重新启动应用程序之前,更改不会反映在组合框中。我到处都[myComboBox reloadData]抹了抹灰,但是没有效果。任何想法我应该寻找什么?

数据源在 IB 中标注:

实现了以下数据源方法:

- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)categoryCombo{


    //NSLog(@"categoryMutableArray count: %lu", (unsigned long)categoryMutableArray.count);
    return categoryMutableArray.count;
}


- (id)comboBox:(NSComboBox *)categoryCombo objectValueForItemAtIndex:(NSInteger)row {
    //NSLog(@"%s", __FUNCTION__);

    [self refreshCategories:nil];

    currentCategory  = [categoryMutableArray objectAtIndex:row];
    mainCategory.stringValue = [currentCategory valueForKey:@"catName"];

    return mainCategory.stringValue;

}


- (void)comboBoxSelectionDidChange:(NSNotification *)notification {
    //NSLog(@"%s", __FUNCTION__);

    currentItem = [mainMutableArray objectAtIndex:rowNumber];

    //[self.mainCategory setStringValue:
    // [NSString stringWithFormat: @"%@", [categoryMutableArray objectAtIndex: [(NSComboBox *)[notification object] indexOfSelectedItem]]]];

    currentCategory = [categoryMutableArray objectAtIndex: [(NSComboBox *)[notification object] indexOfSelectedItem]];
    NSString *newCatString = [currentCategory valueForKey:@"catName"];

    [currentItem setObject:newCatString forKey:@"category"];
    [currentItem saveInBackground];

    //NSLog(@"new category name may be: %@",[currentDream valueForKey:@"category"]);
}
4

0 回答 0