views:

72

answers:

1

I would like to save an array of view controllers in NSUserDefaults, but I am not sure how:

[[NSUserDefaults standardUserDefaults] setObject:tabBarController.viewControllers forKey:@"tabOrder"];

When I read the above line, my tabBarController.viewControllers is blank.

+1  A: 

The view controllers in this array are not serializable, and thus won't be saved to NSUserDefaults.

From the NSUserDefaults reference:

The value parameter can be only property list objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. For NSArray and NSDictionary objects, their contents must be property list objects. See “What is a Property List?” in Property List Programming Guide.

You should re-initialize your view controllers on the next load. You can however serialize their data to NSUserDefaults to some custom fields.

MrMage