Stormotion-Mobile / LUNSegmentedControl

Customizable segmented control with interactive animation.
stormotion.io
MIT License
349 stars 42 forks source link

Unable to set current state until viewDidAppear #13

Closed nderkach closed 7 years ago

nderkach commented 7 years ago

It seems that it's impossible to set the default slider state (setCurrentState) until viewDidAppear. I've tried both in viewWillAppear and viewDidLayoutSubviews.

nderkach commented 7 years ago

Finally I was able to set it in viewDidLayoutSubviews. You need to update the initial state after the view is laid out.

AnthoPakPak commented 7 years ago

There was a delay for me using viewDidLayoutSubviews, so the user notice it. But I found another way. For anyone searching for this, you have to set currentState in viewDidLoad but you have to call [self.view layoutIfNeeded] right before !

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view layoutIfNeeded];
    self.nbTeamsSegmentedControl.currentState = oldSelectedNbTeamsIndex; //saved in NSUserDefaults
}