FLEXSingleRowSection.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // FLEXSingleRowSection.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 9/25/19.
  6. // Copyright © 2019 Flipboard. 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. @end
  14. @implementation FLEXSingleRowSection
  15. @synthesize title = _title;
  16. #pragma mark - Public
  17. + (instancetype)title:(NSString *)title
  18. reuse:(NSString *)reuse
  19. cell:(void (^)(__kindof UITableViewCell *))config {
  20. return [[self alloc] initWithTitle:title reuse:reuse cell:config];
  21. }
  22. - (id)initWithTitle:(NSString *)sectionTitle
  23. reuse:(NSString *)reuseIdentifier
  24. cell:(void (^)(__kindof UITableViewCell *))cellConfiguration {
  25. self = [super init];
  26. if (self) {
  27. _title = sectionTitle;
  28. _reuseIdentifier = reuseIdentifier ?: kFLEXDefaultCell;
  29. _cellConfiguration = cellConfiguration;
  30. }
  31. return self;
  32. }
  33. #pragma mark - Overrides
  34. - (NSInteger)numberOfRows {
  35. if (self.filterMatcher && self.filterText.length) {
  36. return self.filterMatcher(self.filterText) ? 1 : 0;
  37. }
  38. return 1;
  39. }
  40. - (BOOL)canSelectRow:(NSInteger)row {
  41. return self.pushOnSelection || self.selectionAction;
  42. }
  43. - (void (^)(UIViewController *))didSelectRowAction:(NSInteger)row {
  44. return self.selectionAction;
  45. }
  46. - (UIViewController *)viewControllerToPushForRow:(NSInteger)row {
  47. return self.pushOnSelection;
  48. }
  49. - (NSString *)reuseIdentifierForRow:(NSInteger)row {
  50. return self.reuseIdentifier;
  51. }
  52. - (void)configureCell:(__kindof UITableViewCell *)cell forRow:(NSInteger)row {
  53. cell.textLabel.text = nil;
  54. cell.detailTextLabel.text = nil;
  55. cell.accessoryType = UITableViewCellAccessoryNone;
  56. self.cellConfiguration(cell);
  57. }
  58. @end