Cocoa - 重新加载NSComboBox(OSX)

时间:2014-04-25 17:01:35

标签: objective-c cocoa osx-mavericks nscombobox

::编辑 - 解决..我没有正确地符合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"]);
}

0 个答案:

没有答案