SelectedSegmentIndex does not update UISegmentControl

In my DidLoad view, I retrieve the user preferences and refresh the settings tab. It works for editSelection (see Code), but another

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 editToggle segment displays correctly, but is bToggle always 0? NSLog indicates that the data has been saved and retrieved correctly. I even installed

  bToggle.selectedSegmentIndex = 1; 

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

+4
source share
2 answers

Just guessing: is bToggle not connected in Interface Builder?

+8
source

One more question. You cannot put initialization code for segmented controls in init because the view is not yet displayed on the screen. I put it in viewDidLoad and now it works fine.

+2
source

Source: https://habr.com/ru/post/1308207/


All Articles