0

so i have this segmented control in the interface i am using user defaults to store the selected segment in applications view controller's applicationDidEnterBackground and restoring it in - (void)applicationWillEnterForeground {

NSNumber *indexNumber;

if (indexNumber = [[NSUserDefaults standardUserDefaults] objectForKey:@"selectedIndex"]) {

NSInteger selectedIndex = [indexNumber integerValue]; self.segmentedControl.selectedSegmentIndex = selectedIndex; }

but when im launching the app, selecting a segment and then killing the application, i get this error. Program received signal: “SIGKILL” on relaunch.

any help would be appreciated

Ramuel
  • 59
  • 8

1 Answers1

0

Hard to tell without more info, but likely this is caused because the controller and segmented control are not available in applicationWillEnterForeground. (They haven't been instantiated yet.)

You might need more this to the viewDidLoad of the viewController.

NWCoder
  • 5,296
  • 1
  • 26
  • 23
  • so `viewDidLoad` gets called after `applicationWillEnterForeground` ? – Ramuel Mar 11 '11 at 03:09
  • Yes it will get called only once the view is ready, which will be after the processing in the applicationWillEnterForeground is complete. – NWCoder Mar 11 '11 at 18:42
  • moving the code in `ViewDidload` worked like a charm for me. so im studying "beginning iphone 4 developments" by appress, the author stated the code should be in viewDidLoad without any reasons, or maybe i have missed it. so is there any reference to check out before posting on the forums for more information? – Ramuel Mar 11 '11 at 23:12