InAppSettingsKit icon indicating copy to clipboard operation
InAppSettingsKit copied to clipboard

How to ask InAppSettingsKit to reload the settings.

Open charlesmchen opened this issue 13 years ago • 8 comments

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?

charlesmchen avatar Aug 16 '12 15:08 charlesmchen

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?

futuretap avatar Aug 16 '12 15:08 futuretap

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?

Gui13 avatar Dec 17 '13 16:12 Gui13

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

futuretap avatar Dec 17 '13 22:12 futuretap

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

vanderneut avatar Sep 24 '14 05:09 vanderneut

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

neospirit avatar Dec 22 '14 17:12 neospirit

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

futuretap avatar Dec 22 '14 18:12 futuretap

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.

mmahkamov avatar Oct 25 '16 07:10 mmahkamov

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)
    ...
}

jlyonsmith avatar Dec 03 '16 20:12 jlyonsmith