問題:
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