// // RASettingSelectionModel.m // Apex And Drivers // // Created by Jack on 2018/9/12. // Copyright © 2018年 USAI. All rights reserved. // #import "RASettingOptionModel.h" @implementation RASettingOption - (void)setValue:(id)value forUndefinedKey:(NSString *)key { } @end @implementation RASettingOptionModel - (CGFloat)height { return 60.0f; } - (void)setOption:(RASettingOption *)option { _option = option; if (self.delegate && [self.delegate respondsToSelector:@selector(refreshUI)]) { [self.delegate refreshUI]; } if (option && self.keyPath.length > 0) { [RASingleton.sharedInstance setValue:@(option.option) forKeyPath:self.keyPath]; } } - (void)setKeyPath:(NSString *)keyPath { _keyPath = keyPath; if (self.options.count > 0 && _keyPath.length > 0) { [self.options enumerateObjectsUsingBlock:^(RASettingOption * _Nonnull model, NSUInteger idx, BOOL * _Nonnull stop) { if (model.option == [[RASingleton.sharedInstance valueForKeyPath:self.keyPath] intValue]) { self.option = model; } }]; } } - (void)setOptions:(NSArray *)options { if (!options) { _options = nil; return; } NSMutableArray *arr = [NSMutableArray array]; for (NSDictionary *option in options) { RASettingOption *model = [RASettingOption new]; [model setValuesForKeysWithDictionary:option]; if (self.keyPath.length > 0) { if (model.option == [[RASingleton.sharedInstance valueForKeyPath:self.keyPath] intValue]) { self.option = model; } } [arr addObject:model]; } _options = arr; } - (int)selectedIndex { if (self.options.count == 0 || self.option == nil || ![self.options containsObject:self.option]) { return -1; } return (int)[self.options indexOfObject:self.option]; } - (void)setSelectedIndex:(int)selectedIndex { if (selectedIndex >= self.options.count) { return; } self.option = [self.options objectAtIndex:selectedIndex]; } @end