| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- //
- // 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
- - (void)setOption:(RASettingOption *)option {
- _option = option;
-
- if (self.delegate && [self.delegate respondsToSelector:@selector(refreshUI)]) {
- [self.delegate refreshUI];
- }
- }
- - (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<RASettingOption *> *)options {
-
- if (!options) {
- _options = nil;
- return;
- }
-
- NSMutableArray<RASettingOption *> *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 {
-
- self.option = [self.options objectAtIndex:self.selectedIndex];
- }
- @end
|