开发者

NSTreeController how to save to file

Hi I am using an NSTreeController to control an NSOutlineView. This application loads bookmarks from file to application. As in the SourceView example in ADC:

http://developer.apple.com/mac/library/samplecode/SourceView/index.html

My questions is how do I save the bookmark to file once user makes the changes. Should I maintain the array/tree internally in my application and save before quitting or 开发者_运维百科is there any easier methods?


You want to reverse the action taking place in the populateOutline method of MyWindowController.m. This method is reading the plist into one dictionary, reading a value from that dictionary, and using it to build the tree. Start with that method and follow the code to see how it is building the tree. It's using the BaseNode and ChildNode classes to build up the data model as a tree (I'm not sure why they didn't just use NSTreeNode). You want to reverse that procedure, ending up with an NSDictionary. You can then use writeToFile:atomically: to save the dictionary back to disk.

This can get as complex as you'd like to make it. For instance, the current code loads the dictionary file in a separate thread, so you could save in a separate thread, too. Or, you might want to save after every edit, again in a separate thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜