【问题标题】:How do I check if a NSView is being displayed at the moment?如何检查当前是否正在显示 NSView?
【发布时间】:2010-01-21 14:02:55
【问题描述】:

我有一个应用程序,它的主窗口中有一个 NSToolbar。根据单击的图标,此窗口中会显示 NSView。我的问题是,这些视图之一显示了 NSTableView 中的数据,每次视图可见时我都希望重新加载这些数据。由于 -init 只被调用一次,我不知道该怎么做。 (例如:当应用程序启动时,它会显示 Documents 部分 [在窗口的子视图中]。现在,当我单击Employees [它显示另一个子视图而不是第一个],然后再次单击 Documents 时,我想要要重新加载 Documents 的 NSTableView 中的数据。)

我该怎么做?

提前致谢。

【问题讨论】:

    标签: cocoa nstableview nsview


    【解决方案1】:

    我有一个应用程序,它的主窗口中有一个 NSToolbar。根据单击的图标,此窗口中会显示 NSView。

    使用标签视图。 You can hide the tabs, then implement your action methods for the toolbar items to act as the tabs, changing the selected tab view item to whichever one corresponds to the pressed toolbar item.

    现在,当我点击Employees [显示另一个子视图而不是第一个],然后再次点击Documents 时,我希望重新加载Documents 的NSTableView 中的数据。

    为什么?为什么不只在数据发生变化时重新加载呢?

    你不必牵着 NSTableView 的手;如果它再次需要您的数据,它会再次向您询问。

    如果您担心在视图不可见时重新加载数据,那就是过早的优化。在您通过分析证明这是一个真正的性能问题之前,请不要担心。

    【讨论】:

    • 是的,通常 NSTableView 在不可见时不刷新非常好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-12
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多