开发者

How do I edit and save a nib file at runtime?

Imagine an application that has a number of buttons it is displaying to the user. This application wants to allow the user to move the buttons around on the screen, customizing the display, and then save this configuration for later use. That is, when the app is close开发者_StackOverflow社区d and relaunched, it will come back up with the same configuration.

I would like to create a nib file with the "factory default" button layout, but then create a new nib file storing the new UI after the user has configured it just the way they like it. How does one do this?

Thanks!


Have a look at

 NSData * viewData = [NSKeyedArchiver archivedDataWithRootObject:yourView];
 NSView * yourView =[NSKeyedUnarchiver unarchiveObjectWithData:viewData];

This will do what you want. With all subviews, properties etc.


you really don't create a new nib.

for one, you can't expect the user to have the devtools installed. so you need to implement these dynamic parts programmatically.

perhaps export a dictionary with colors, positions, etc. for the mutable properties; then apply those properties to those objects (so it's quite like a simple layer over a nib's xml representation).

if you are not currently using tags to identify your nib's objects, that may be an easy way to identify objects in your exported dictionary.

good luck

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜