问题:
I created a toolbar in IB with several buttons.我在 IB 中创建了一个带有几个按钮的工具栏。 I would like to be able to hide/show one of the buttons depending on the state of the data in the main window.我希望能够根据主窗口中的数据状态隐藏/显示按钮之一。
UIBarButtonItem
doesn't have a hidden property, and any examples I've found so far for hiding them involve setting nav bar buttons to nil, which I don't think I want to do here because I may need to show the button again (not to mention that, if I connect my button to an IBOutlet, if I set that to nil I'm not sure how I'd get it back). UIBarButtonItem
没有隐藏属性,到目前为止我发现的任何隐藏它们的示例都涉及将导航栏按钮设置为零,我认为我不想在这里这样做,因为我可能需要再次显示按钮(更不用说,如果我将我的按钮连接到 IBOutlet,如果我将其设置为 nil,我不确定如何将其取回)。
解决方案:
参考一: https://en.stackoom.com/question/g376参考二: https://stackoom.com/question/g376