Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current state is not set properly when segmented control changes width #12

Open
dashvlas opened this issue Nov 5, 2016 · 7 comments
Open
Labels

Comments

@dashvlas
Copy link

dashvlas commented Nov 5, 2016

I want to save selected tab so that when application will be closed and opened again previously selected tab will be in selected state. How can I do this? It's always launched with first tab.

I used currentState property with delegate methods, but nothing works.
Please, help

@nin-amsiq
Copy link

You can save the state in a UserDefault to persist data between sessions.

@dashvlas
Copy link
Author

It's obvious, I did it with NSUserDefaults, but when I terminate the app state hadn't saved

@AnthoPakPak
Copy link

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
}

@lennondong
Copy link

lennondong commented Aug 3, 2018

@dashvlas Did you resolve it? currentState is not working.

@dashvlas
Copy link
Author

dashvlas commented Aug 3, 2018

@lennondong Unfortunately no :(
I stopped using it.
You can install this pod but you have to edit some files in framework in order to save current state

@dashvlas dashvlas closed this as completed Aug 3, 2018
@dashvlas dashvlas reopened this Aug 3, 2018
@lennondong
Copy link

@dashvlas thank for your reply. Finally I resolve it. Now I have use it in my app.

@seland
Copy link
Collaborator

seland commented Mar 28, 2020

@dashvlas Sorry for the inconvenience, it was not possible to maintain the library for a long time because of access issues.
Underlying bug is that currentState setter relied on the fact that segmented control is already laid out, which is not the case in viewDidLoad. Setting it in viewDidAppear instead would workaround the issue, but it's surely a bug.

@seland seland changed the title Can't save state Current state is not set properly when segmented control changes width Mar 28, 2020
@seland seland added the bug label Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants