Alderis icon indicating copy to clipboard operation
Alderis copied to clipboard

Picker reappears when specifier's property changed programmatically

Open udevsharold opened this issue 4 years ago • 0 comments

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

udevsharold avatar Jun 02 '20 07:06 udevsharold