Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selectedSegmentIndex not updating UISegmentControl

In my viewDidLoad, I'm retrieving user preferences and updating the settings tab. It is working for editSelection (see code) but the other

  NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

  BOOL editSelection = [userDefaults boolForKey:@"editToggleSwitch"];
  editingToggle.selectedSegmentIndex  = editSelection; // this is working!

  bToggle.selectedSegmentIndex = [[userDefaults objectForKey:@"bSegment"] intValue];

In the view, the editingToggle segment is displaying correctly but bToggle is always at 0? NSLog shows that the data was saved and retrieved correctly. I've even set

 bToggle.selectedSegmentIndex = 1;

but it still does not reflect correctly in the view? Any ideas?

like image 705
munchine Avatar asked Dec 28 '22 18:12

munchine


2 Answers

Just guessing: bToggle not wired up in Interface Builder?

like image 68
Nikolai Ruhe Avatar answered Feb 12 '23 12:02

Nikolai Ruhe


One other gotcha. You can't put the initialization code for the segmented controls in the init because the view is not on the screen yet. I put it in viewDidLoad and it works fine now.

like image 37
JScarry Avatar answered Feb 12 '23 12:02

JScarry