Wednesday, August 12, 2009

Embedding a preference bundle, in your app.

If you want to use Preferences.framework in your app, you can do it like this.

First, make a PSListController subclass as you would when creating a Preference Bundle. Then create a subclass of PSRootController, with code like this:
@interface MyRootController : PSRootController
@implementation MyRootController
-(void)setupRootListForSize:(CGSize)size {
PSSpecifier* spec = [[PSSpecifier alloc] init]; = @"Anything";

MyListController* root = [[MyListController alloc] initForContentSize:size];
root.rootController = self;
[root viewWillBecomeVisible:spec];
[spec setTarget:root];
[spec release];
root.parentController = self;

[self pushController:root];
[root release];

Finally, in your app's delegate, write these code:
-(void)applicationDidFinishLaunching:(UIApplication *)application {
window.frame = [UIScreen mainScreen].applicationFrame;
MyRootController* rootCtrler = [[MyRootController alloc] initWithTitle:@"Some Title" identifier:@"com.yourcompany.appName"];
[window addSubview:[rootCtrler contentView]];

Why do this? One major reason it that we can now debug the Pref Bundle in Simulator, and speed up development.

No comments:

Post a Comment