Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何使用代码隐藏NSToolbarItem?_Objective C_Cocoa_Nstoolbar_Nstoolbaritem - Fatal编程技术网

Objective c 如何使用代码隐藏NSToolbarItem?

Objective c 如何使用代码隐藏NSToolbarItem?,objective-c,cocoa,nstoolbar,nstoolbaritem,Objective C,Cocoa,Nstoolbar,Nstoolbaritem,我有一个带有各种选项的工具栏,有些选项在某些情况下不应该可见。我已经找到了在我的应用程序中禁用它们的方法,使用以下回调: - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem 但我还没有找到一种方法,在我需要的时候真正隐藏它们。有没有人知道怎么做,或者这是否真的有可能?如果禁用它们还不够,你可以删除这些项目 [myToolbar removeItemAtIndex:itemIndex]; 然后,当您需要将其放回时,只需重新

我有一个带有各种选项的工具栏,有些选项在某些情况下不应该可见。我已经找到了在我的应用程序中禁用它们的方法,使用以下回调:

  - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem

但我还没有找到一种方法,在我需要的时候真正隐藏它们。有没有人知道怎么做,或者这是否真的有可能?

如果禁用它们还不够,你可以删除这些项目

[myToolbar removeItemAtIndex:itemIndex];
然后,当您需要将其放回时,只需重新插入即可:

[myToolbar insertItemWithItemIdentifier:itemIdentifier atIndex:itemIndex];

查看Apple文档中的内容。

按钮没有内置的可见性属性。将其从工具栏中删除,并在需要时重新添加。

如何重新添加?我没有看到“addItemToToolbar”方法。我能找到的最接近的东西是“-(void)insertItemWithItemIdentifier:(NSString*)itemIdentifier atIndex:(NSInteger)index”。这就是我要找的方法吗?我是否需要在我的代理人身上实施任何其他措施?