且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法在NSView中隐藏控件

更新时间:2023-02-20 18:32:47

不知道应用程序中还发生了什么,很难知道为什么这不会使按钮隐藏。

Without knowing what else is going on in the application it is hard to know why this would not be making the button hidden.

是您阻止主事件循环,以便不处理更新事件?通常,这不是一件好事。

Are you blocking the main event loop such that the update events are not getting handled? Generally this is not a good thing to do.

可以强制执行立即更新的一件事是在按钮或其父视图或窗口上调用displayIfNeeded。这将导致重新绘制视图。这适合作为验证按钮将绘制(或不绘制)其正确状态的实验。如果调用displayIfNeeded确实导致它消失,那么您将需要确定为什么未正确处理更新事件。

One thing you can do to force an immediate update is to call displayIfNeeded on the button or its parent view or window. This should cause the view to be redrawn. This would be suitable as an experiment to validate that the button will draw (or not draw) its correct state. If calling displayIfNeeded does cause it to disappear then you will need to determine why update events are not getting handled correctly.