hbang / Alderis

A fresh new color picker, with a gentle, fun, and dead simple user interface.

Home Page:https://hbang.github.io/Alderis/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Picker reappears when specifier's property changed programmatically

udevsharold opened this issue · comments

commented

I'm implementing this in one of my tweak, and the picker specifiers are dynamically enabled and disabled based on a switch. Every time the switch is toggled, last picker (it consist of three pickers in prefs) will pop-up. I'm not sure is this issue occurs because of how I implement it, or it's on how Alderis' implementation. Sample code:

In RootListController.m:

- (NSArray *)specifiers {
    if (!_specifiers) {
        _specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
        NSArray *pickerCell = @[@"picker1", @"picker2",@"picker3"];
        self.pickerSpecifiers = (!self.pickerSpecifiers) ? [[NSMutableDictionary alloc] init] : self.pickerSpecifiers ;
        for(PSSpecifier *specifier in _specifiers) {
            if([pickerCell containsObject:[specifier propertyForKey:@"tag"]]) {
                [self.pickerSpecifiers setObject:specifier forKey:[specifier propertyForKey:@"tag"]];
            }
        }
    }
    return _specifiers;
}

- (void)setPreferenceValue:(id)value specifier:(PSSpecifier *)specifier{
    [super setPreferenceValue:value specifier:specifier];
    NSString *key = [specifier propertyForKey:@"key"];
    if([key isEqualToString:@"theswitch"]) {
        [(PSSpecifier *)self.pickerSpecifiers [@"picker1tag"] setProperty:value forKey:@"enabled"];
        [self reloadSpecifier:(PSSpecifier *)self.pickerSpecifiers [@"pickertag1"] animated:NO]; //It should be this line caused the last picker to pop-up to due to the reloading
    }
}