退出后保持完整应用程序的状态
我在关闭 Mac OS X 应用程序(在 Lion 上运行)时无法保持它的状态 - 它当前在窗口中只有一个 NSTextView,我想保持窗口大小和实际在我的文本中的文本的状态NSTextView 以及应用程序下次加载时的格式。
因此,我想知道是否有人可以给我一个指针(哈,明白了 - 指针?)关于如何保持我的应用程序的状态,这样当应用程序退出后再次打开时它是一样的。提前致谢。
I am having trouble keeping the state of my Mac OS X app (running on Lion) when it is closed - it currently only has an NSTextView in the window and I want to keep the state of the window size and the text that's actually in my NSTextView along with its formatting for when the application next loads up.
I was therefore wondering if anyone could give me a pointer (ha, get it - pointer?) as to how to go about keeping the state of my application so it's the same when the application is opened again once quit. Thanks in advanced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅使用 NSUserDefaults 类将信息存储在用户默认值中,然后在应用程序启动时重新加载这些设置有什么问题吗?
在 XIB 中,您可以将窗口设置为“启动时不可见”。然后,您可以在 AppDelegate 中实现 applicationDidFinishLaunching ,并在那里进行适当的设置 - 该方法中的最后一行代码是使应用程序的窗口可见。通过这种方式,您可以避免任何用户混淆,并且应用程序将看起来活泼且响应迅速,即在应用程序完全加载之前,没有任何内容可见。
What's wrong with just storing your information in the user defaults using the NSUserDefaults class, and then loading those settings back in when the application launches?
In the XIB, you can set your window to "not visible at startup". You can then implement
applicationDidFinishLaunching
in your AppDelegate, do the appropriate setup there - the final line of code in that method would be to make the app's window visible. This way you avoid any user confusion and the app will look snappy and responsive, i.e. until the app is fully loaded nothing becomes visible.