Problem with NSUserDefaults and deallocated Instance
Posted
by Peter A
on Stack Overflow
See other posts from Stack Overflow
or by Peter A
Published on 2010-03-08T08:59:25Z
Indexed on
2010/03/11
17:29 UTC
Read the original article
Hit count: 430
nsuserdefaults
Hi,
I'm having a problem with NSUserDefaults. I've followed the steps in the books as closely as I can for my app, but still get the same problem.
I am getting a
*** -[NSUserDefaults integerForKey:]: message sent to deallocated instance 0x3b375a0
error when I try and load in the settings. Here is the code that I have, it is in the App Delegate class.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
recordingController = [[RecordingTableViewController alloc] initWithStyle:UITableViewStylePlain];
[recordingController retain];
// Add the tab bar controller's current view as a subview of the window
[window addSubview:tabBarController.view];
[self loadSettings];
}
-(void)loadSettings
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber loop = [defaults objectForKey:@"loop_preference"];
NSNumber play = [defaults objectForKey:@"play_me_preference"];
NSNumber volume = [defaults objectForKey:@"volume_preference"];
}
As you can see I am not trying to do anything with the values yet, but I get the error on the line reading in the loop preference. I also get it if I try and read an NSString.
Any suggestions would be greatly appreciated.
Thanks
Peter
© Stack Overflow or respective owner