如何保存 NSCollectionView 的内容?
我有一个 nscollectionview ,其中包含用户可以添加/删除的集合项。每个集合项都包含一个文本视图和一个图像视图。我已经设法使用 NSSavePanel 将字符串保存到文件中,但是如何获取 textview 和 imageview 的内容,以便我可以通过迭代保存集合项的数组将它们保存到数组中?
或者
有没有更好的方法来保存集合项的内容?
谢谢
I have an nscollectionview which holds collectionitems which the user can add/delete. Each collectionitem holds a textview and an imageview. I have managed so save strings to files using NSSavePanel but how would I get the contents of the textview and imageview so I can save them to an array by iterating through the array holding the collectionitems?
or
Is there a better way to save the contents of the collectionitem?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只有您可以决定如何最好地保留应用程序的数据,但您需要了解视图(集合视图及其项目的视图)和模型(由视图表示的事物,由控制器安排和管理)之间的区别。
那么:既然你的集合视图显示了一系列的东西,那么保存这一系列的东西没有意义吗?确保数组中的内容可序列化< /a> 然后使用 NSArray 的 -writeToURL :atomically: 方法将数组及其可序列化内容写入文件。
请记住,您不是在保存视图,而是在保存视图表示的数据(并由控制器层介导/控制/管理)。请参阅模型-视图-控制器设计模式 了解更多信息。
Only you can decide how best to persist your application's data, but you need to understand the difference between your view (the collection view and its items' views) and your model (the things represented by the views, arranged and managed by the controller).
So: Since your collection view is showing an array of things, doesn't it make sense to save that array of things? Make sure the things in the array are serializable then use NSArray's -writeToURL:atomically: method to write the array and its serializable content out to a file.
Just remember, you're not saving your view, you're saving the data represented by the view (and mediated/controlled/managed by the controller layer). See the Model-View-Controller design pattern for more information.