FLEXExplorerSection.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // FLEXExplorerSection.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/28/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @class FLEXTableView;
  10. #pragma mark FLEXExplorerSection
  11. /// An abstract base class for custom object explorer sections.
  12. @interface FLEXExplorerSection : NSObject
  13. #pragma mark - Data
  14. /// A title to be displayed for the custom section. Subclasses must override.
  15. @property (nonatomic, readonly) NSString *title;
  16. /// The number of rows in this section.
  17. /// This should not change until \c filterText is changed or \c reloadData is called.
  18. @property (nonatomic, readonly) NSInteger numberOfRows;
  19. /// A map of reuse identifiers to \c UITableViewCell (sub)class objects.
  20. /// Subclasses \e may override this as necessary, but are not required to.
  21. /// See \c FLEXTableView.h for more information.
  22. /// @return nil by default.
  23. @property (nonatomic, readonly) NSDictionary<NSString *, Class> *cellRegistrationMapping;
  24. /// The section should filter itself based on the contents of this property
  25. /// as it is set. If it is set to nil or an empty string, it should not filter.
  26. /// Subclasses should override or observe this property and react to changes.
  27. @property (nonatomic) NSString *filterText;
  28. /// Provides an avenue for the section to change the number of rows.
  29. /// This is called before reloading the table view itself.
  30. - (void)reloadData;
  31. #pragma mark - Row selection
  32. /// Whether the given row should be selectable, such as if tapping the cell
  33. /// should take the user to a new screen or trigger an action.
  34. /// Subclasses \e may override this as necessary, but are not required to.
  35. /// @return \c NO by default
  36. - (BOOL)canSelectRow:(NSInteger)row;
  37. /// An action "future" to be triggered when the row is selected, if the row
  38. /// supports being selected as indicated by \c canSelectRow:. Subclasses
  39. /// must implement this in accordance with how they implement \c canSelectRow:
  40. /// if they do not implement \c viewControllerToPushForRow:
  41. /// @return This returns \c nil if no view controller is provided by
  42. /// \c viewControllerToPushForRow: — otherwise it pushes that view controller
  43. /// onto \c host.navigationController
  44. - (void(^)(UIViewController *host))didSelectRowAction:(NSInteger)row;
  45. /// A view controller to display when the row is selected, if the row
  46. /// supports being selected as indicated by \c canSelectRow:. Subclasses
  47. /// must implement this in accordance with how they implement \c canSelectRow:
  48. /// if they do not implement \c didSelectRowAction:
  49. /// @return \c nil by default
  50. - (UIViewController *)viewControllerToPushForRow:(NSInteger)row;
  51. /// Called when the accessory view's detail button is pressed.
  52. /// @return \c nil by default.
  53. - (void(^)(UIViewController *host))didPressInfoButtonAction:(NSInteger)row;
  54. #pragma mark - Cell configuration
  55. /// Provide a reuse identifier for the given row. Subclasses should override.
  56. ///
  57. /// Custom reuse identifiers should be specified in \c cellRegistrationMapping.
  58. /// You may return any of the identifiers in \c FLEXTableView.h
  59. /// without including them in the \c cellRegistrationMapping.
  60. /// @return \c kFLEXDefaultCell by default.
  61. - (NSString *)reuseIdentifierForRow:(NSInteger)row;
  62. /// Configure a cell for the given row. Subclasses must override.
  63. - (void)configureCell:(__kindof UITableViewCell *)cell forRow:(NSInteger)row;
  64. #pragma mark - External Convenience
  65. /// For use by whatever view controller uses your section. Not required.
  66. /// @return An optional title.
  67. - (NSString *)titleForRow:(NSInteger)row;
  68. /// For use by whatever view controller uses your section. Not required.
  69. /// @return An optional subtitle.
  70. - (NSString *)subtitleForRow:(NSInteger)row;
  71. @end
  72. #pragma mark - FLEXObjectInfoSection
  73. /// \c FLEXExplorerSection itself doesn't need to know about the object being explored.
  74. /// Subclasses might need this info to provide useful information about the object. Instead
  75. /// of adding an abstract class to the class hierarchy, subclasses can conform to this protocol
  76. /// to indicate that the only info they need to be initialized is the object being explored.
  77. @protocol FLEXObjectInfoSection <NSObject>
  78. + (instancetype)forObject:(id)object;
  79. @end