RASettingOptionModel.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // RASettingSelectionModel.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/9/12.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RASettingOptionModel.h"
  9. @implementation RASettingOption
  10. - (void)setValue:(id)value forUndefinedKey:(NSString *)key {
  11. }
  12. @end
  13. @implementation RASettingOptionModel
  14. - (void)setOption:(RASettingOption *)option {
  15. _option = option;
  16. if (self.delegate && [self.delegate respondsToSelector:@selector(refreshUI)]) {
  17. [self.delegate refreshUI];
  18. }
  19. }
  20. - (void)setKeyPath:(NSString *)keyPath {
  21. _keyPath = keyPath;
  22. if (self.options.count > 0 && _keyPath.length > 0) {
  23. [self.options enumerateObjectsUsingBlock:^(RASettingOption * _Nonnull model, NSUInteger idx, BOOL * _Nonnull stop) {
  24. if (model.option == [[RASingleton.sharedInstance valueForKeyPath:self.keyPath] intValue]) {
  25. self.option = model;
  26. }
  27. }];
  28. }
  29. }
  30. - (void)setOptions:(NSArray<RASettingOption *> *)options {
  31. if (!options) {
  32. _options = nil;
  33. return;
  34. }
  35. NSMutableArray<RASettingOption *> *arr = [NSMutableArray array];
  36. for (NSDictionary *option in options) {
  37. RASettingOption *model = [RASettingOption new];
  38. [model setValuesForKeysWithDictionary:option];
  39. if (self.keyPath.length > 0) {
  40. if (model.option == [[RASingleton.sharedInstance valueForKeyPath:self.keyPath] intValue]) {
  41. self.option = model;
  42. }
  43. }
  44. [arr addObject:model];
  45. }
  46. _options = arr;
  47. }
  48. - (int)selectedIndex {
  49. if (self.options.count == 0 || self.option == nil || ![self.options containsObject:self.option]) {
  50. return -1;
  51. }
  52. return (int)[self.options indexOfObject:self.option];
  53. }
  54. - (void)setSelectedIndex:(int)selectedIndex {
  55. self.option = [self.options objectAtIndex:self.selectedIndex];
  56. }
  57. @end