无法从NSPopUpButton中删除项目

时间:2015-03-02 19:23:32

标签: objective-c xcode cocoa nspopupbutton

我正在尝试从NSPopUpButton中移除项目,但似乎这不起作用

我试过了:

[self.myMenu removeAllItems];

还有:

    NSInteger items = [_myMenu numberOfItems];

    for (NSInteger i = (items -1) ; i >= 0 ; i--)
    {
        [self.myMenu removeItemAtIndex:i];
    }

但如果我在控制台中查看myMenu(NSPopUpButton)的计数,我会得到这个:

p [_myMenu numberOfItems] (NSInteger)$ 3 = 0

但我在应用程序窗口中检查NSPopUpButton我仍然拥有所有项目。你们中的任何人都知道我做错了什么,如果这是一个删除项目的技巧?

我真的很感谢你的帮助。

1 个答案:

答案 0 :(得分:2)

NSPopupButton提供3个用于删除项目的API。

1)removeAllItems 2)removeItemWithTitle:(NSString *)标题 3)removeItemAtIndex:(NSInteger)索引

在您的情况下,无需访问菜单。你可以直接这样打电话 [popupButton removeItemAtIndex:0];