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

How to ask InAppSettingsKit to reload the settings. #171

Open
charlesmchen opened this issue Aug 16, 2012 · 8 comments
Open

How to ask InAppSettingsKit to reload the settings. #171

charlesmchen opened this issue Aug 16, 2012 · 8 comments

Comments

@charlesmchen
Copy link

I've got a resetToDefaults() method that overwrites all of the app's settings. I don't see any means in InAppSettingsKit's API to ask it to reload the settings. Can this be added? Am I missing something?

@futuretap
Copy link
Owner

IASK automatically updates the views when the underlying NSUserDefaults are changed. This is done by observing the NSUserDefaults change notification. Or did I misunderstand your question?

@Gui13
Copy link

Gui13 commented Dec 17, 2013

What happens if you're using a private implementation of IASKAbstractSettingsStore?
I'm facing the same issue, where I have my configuration that has changed internally, but I can't update the rows and they show the old values. Changing the settingStore doesn't make the underlying cached tables reload their values.

Marking -userDefaultsDidChange public doesn't solve the problem either, since the method only operates on user defaults, not private implementations.

Would it be possible to detect settingStore changes and force-reload the existing views?

@futuretap
Copy link
Owner

Currently, automatic reloading is only implemented for NSUserDefaults. We'd gladly accept a pull request to generalize this for all stores. ;-)

@vanderneut
Copy link

I am also looking for this feature. I need the Settings view to update itself even though the underlying NSUserDefaults have not changed, because I need to be able to update all the labels whenever the user choses a new user interface language. (Believe me that I have a reason why I am giving the user the option to change the user interface language, overriding the default behavior of the app taking the user interface language from the device language.)

When the user choses a different interface language, than my settings view controller (which extends the IASKAppSettingsViewController) detects that, does its thing, and traces out to the console proof that NSLocalizedString() is now returning the messages localized into the selected language.

At that point I am then wanting to update the Settings view itself so that it reloads all the text so it's all localized. I have tried all of the following, to no avail:

[self.view setNeedsDisplay];
[super viewDidLoad];
[super viewWillAppear:YES];
[self.tableView reloadData];

:-(

Any tips?

Thanks,
Erik

@neospirit
Copy link

Hi.
I have kind a way a similar request. Sometimes my application download the settings file from a server. When it's downloaded and I open the InAppSettingsKitViewController, the informations displayed are the old one. My file downloaded from the server is not loaded.

How can I do that please ?

Thks
Cyrille

@futuretap
Copy link
Owner

@neospirit Cyrille, when you change the NSUserDefaults in your fetch method, IASK should automatically update the view.

@mmahkamov
Copy link

If anyone's still interested, here's how you reload the settings after changes in custom settings store.

InAppSettingsKit posts a notification when settings change - kIASKAppSettingChanged.
However, it subscribes to kIASKAppSettingChanged only when using the default settings store.

To solve the issue, we subscribe to kIASKAppSettingChanged. I'm assuming that your class is inherited from IASKAppSettingsViewController.

// this is to gain access to the IASKAppSettingsViewController's private methods
@interface IASKAppSettingsViewController()

- (void)reload;

@end

@interface CustomSettingsViewController ()
@end

@implementation CustomSettingsViewController

- (id)init {
    self = [super init];

    if(self) {
        self.settingsStore = [[CustomSettingsStore alloc] init];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(settingsChanged:)
                                                     name:kIASKAppSettingChanged
                                                   object:nil];
    }

    return self;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kIASKAppSettingChanged object:nil];
}

- (void)settingsChanged:(NSNotification*)notification {
    [super reload];
}

@end

IASKAppSettingsViewController:reload is private, so we expose it using a category.

@jlyonsmith
Copy link

jlyonsmith commented Dec 3, 2016

With Swift 3.0 I did something a little different because you cannot expose private functions using categories. In my case I just want to reload the settings in my custom cell views, which is specifically filtered out in the default handling of the NSNotification message. So I do:

func settingsViewController(_ sender: IASKAppSettingsViewController!, buttonTappedFor specifier: IASKSpecifier!) {
    ...   
    UserDefaults.standard.synchronize()
    // This is what is done in InAppSettingsKit to reload
    sender.tableView.perform(#selector(UITableView.reloadData), with: nil, afterDelay: 0.5)
    ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants