FLEXMutableListSection.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // FLEXMutableListSection.h
  3. // FLEX
  4. //
  5. // Created by Tanner on 3/9/20.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXCollectionContentSection.h"
  9. typedef void (^FLEXMutableListCellForElement)(__kindof UITableViewCell *cell, id element, NSInteger row);
  10. /// A section aimed at meeting the needs of table views with one section
  11. /// (or, a section that shouldn't warrant the code duplication that comes
  12. /// with creating a new section just for some specific table view)
  13. ///
  14. /// Use this section if you want to display a growing list of rows,
  15. /// or even if you want to display a static list of rows.
  16. ///
  17. /// To support editing or inserting, implement the appropriate
  18. /// table view delegate methods in your table view delegate class
  19. /// and call \c mutate: (or \c setList: ) before updating the table view.
  20. ///
  21. /// By default, no section title is shown. Assign one to \c customTitle
  22. ///
  23. /// By default, \c kFLEXDetailCell is the reuse identifier used. If you need
  24. /// to support multiple reuse identifiers in a single section, implement the
  25. /// \c cellForRowAtIndexPath: method, dequeue the cell yourself and call
  26. /// \c -configureCell: on the appropriate section object, passing in the cell
  27. @interface FLEXMutableListSection<__covariant ObjectType> : FLEXCollectionContentSection
  28. /// Initializes a section with an empty list.
  29. + (instancetype)list:(NSArray<ObjectType> *)list
  30. cellConfiguration:(FLEXMutableListCellForElement)configurationBlock
  31. filterMatcher:(BOOL(^)(NSString *filterText, id element))filterBlock;
  32. /// By default, rows are not selectable. If you want rows
  33. /// to be selectable, provide a selection handler here.
  34. @property (nonatomic, copy) void (^selectionHandler)(__kindof UIViewController *host, id element);
  35. /// The objects representing all possible rows in the section.
  36. @property (nonatomic) NSArray<ObjectType> *list;
  37. /// The objects representing the currently unfiltered rows in the section.
  38. @property (nonatomic, readonly) NSArray<ObjectType> *filteredList;
  39. /// A readwrite version of the same property in \c FLEXTableViewSection.h
  40. ///
  41. /// This property expects one entry. An exception is thrown if more than one
  42. /// entry is supplied. If you need more than one reuse identifier within a single
  43. /// section, your view probably has more complexity than this class can handle.
  44. @property (nonatomic, readwrite) NSDictionary<NSString *, Class> *cellRegistrationMapping;
  45. /// Call this method to mutate the full, unfiltered list.
  46. /// This ensures that \c filteredList is updated after any mutations.
  47. - (void)mutate:(void(^)(NSMutableArray *list))block;
  48. @end