FLEXSingleRowSection.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // FLEXSingleRowSection.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 9/25/19.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXSingleRowSection.h"
  9. #import "FLEXTableView.h"
  10. @interface FLEXSingleRowSection ()
  11. @property (nonatomic, readonly) NSString *reuseIdentifier;
  12. @property (nonatomic, readonly) void (^cellConfiguration)(__kindof UITableViewCell *cell);
  13. @property (nonatomic) NSString *lastTitle;
  14. @property (nonatomic) NSString *lastSubitle;
  15. @end
  16. @implementation FLEXSingleRowSection
  17. #pragma mark - Public
  18. + (instancetype)title:(NSString *)title
  19. reuse:(NSString *)reuse
  20. cell:(void (^)(__kindof UITableViewCell *))config {
  21. return [[self alloc] initWithTitle:title reuse:reuse cell:config];
  22. }
  23. - (id)initWithTitle:(NSString *)sectionTitle
  24. reuse:(NSString *)reuseIdentifier
  25. cell:(void (^)(__kindof UITableViewCell *))cellConfiguration {
  26. self = [super init];
  27. if (self) {
  28. _title = sectionTitle;
  29. _reuseIdentifier = reuseIdentifier ?: kFLEXDefaultCell;
  30. _cellConfiguration = cellConfiguration;
  31. }
  32. return self;
  33. }
  34. #pragma mark - Overrides
  35. - (NSInteger)numberOfRows {
  36. if (self.filterMatcher && self.filterText.length) {
  37. return self.filterMatcher(self.filterText) ? 1 : 0;
  38. }
  39. return 1;
  40. }
  41. - (BOOL)canSelectRow:(NSInteger)row {
  42. return self.pushOnSelection || self.selectionAction;
  43. }
  44. - (void (^)(__kindof UIViewController *))didSelectRowAction:(NSInteger)row {
  45. return self.selectionAction;
  46. }
  47. - (UIViewController *)viewControllerToPushForRow:(NSInteger)row {
  48. return self.pushOnSelection;
  49. }
  50. - (NSString *)reuseIdentifierForRow:(NSInteger)row {
  51. return self.reuseIdentifier;
  52. }
  53. - (void)configureCell:(__kindof UITableViewCell *)cell forRow:(NSInteger)row {
  54. cell.textLabel.text = nil;
  55. cell.detailTextLabel.text = nil;
  56. cell.accessoryType = UITableViewCellAccessoryNone;
  57. self.cellConfiguration(cell);
  58. self.lastTitle = cell.textLabel.text;
  59. self.lastSubitle = cell.detailTextLabel.text;
  60. }
  61. - (NSString *)titleForRow:(NSInteger)row {
  62. return self.lastTitle;
  63. }
  64. - (NSString *)subtitleForRow:(NSInteger)row {
  65. return self.lastSubitle;
  66. }
  67. @end