FLEXViewControllersViewController.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // FLEXViewControllersViewController.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 2/13/20.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXViewControllersViewController.h"
  9. #import "FLEXObjectExplorerFactory.h"
  10. #import "FLEXMutableListSection.h"
  11. #import "FLEXUtility.h"
  12. @interface FLEXViewControllersViewController ()
  13. @property (nonatomic, readonly) FLEXMutableListSection *section;
  14. @property (nonatomic, readonly) NSArray<UIViewController *> *controllers;
  15. @end
  16. @implementation FLEXViewControllersViewController
  17. @dynamic sections, allSections;
  18. #pragma mark - Initialization
  19. + (instancetype)controllersForViews:(NSArray<UIView *> *)views {
  20. return [[self alloc] initWithViews:views];
  21. }
  22. - (id)initWithViews:(NSArray<UIView *> *)views {
  23. NSParameterAssert(views.count);
  24. self = [self initWithStyle:UITableViewStylePlain];
  25. if (self) {
  26. _controllers = [views flex_mapped:^id(UIView *view, NSUInteger idx) {
  27. return [FLEXUtility viewControllerForView:view];
  28. }];
  29. }
  30. return self;
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. self.title = @"View Controllers at Tap";
  35. self.showsSearchBar = YES;
  36. [self disableToolbar];
  37. }
  38. - (NSArray<FLEXTableViewSection *> *)makeSections {
  39. _section = [FLEXMutableListSection list:self.controllers
  40. cellConfiguration:^(UITableViewCell *cell, UIViewController *controller, NSInteger row) {
  41. cell.textLabel.text = [NSString
  42. stringWithFormat:@"%@ — %p", NSStringFromClass(controller.class), controller
  43. ];
  44. cell.detailTextLabel.text = controller.view.description;
  45. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  46. cell.textLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  47. } filterMatcher:^BOOL(NSString *filterText, UIViewController *controller) {
  48. return [NSStringFromClass(controller.class) localizedCaseInsensitiveContainsString:filterText];
  49. }];
  50. self.section.selectionHandler = ^(UIViewController *host, UIViewController *controller) {
  51. [host.navigationController pushViewController:
  52. [FLEXObjectExplorerFactory explorerViewControllerForObject:controller]
  53. animated:YES];
  54. };
  55. self.section.customTitle = @"View Controllers";
  56. return @[self.section];
  57. }
  58. #pragma mark - Private
  59. - (void)dismissAnimated {
  60. [self dismissViewControllerAnimated:YES completion:nil];
  61. }
  62. @end