TBKeyPathViewController.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // TBKeyPathViewController.m
  3. // TBTweakViewController
  4. //
  5. // Created by Tanner on 3/23/17.
  6. // Copyright © 2017 Tanner Bennett. All rights reserved.
  7. //
  8. #import "TBKeyPathViewController.h"
  9. #import "TBKeyPathSearchController.h"
  10. #import "TBKeyPathToolbar.h"
  11. #import "UIGestureRecognizer+Blocks.h"
  12. //#import "TBCodeFontCell.h"
  13. @interface TBKeyPathViewController () <TBKeyPathSearchControllerDelegate>
  14. @property (nonatomic, readonly ) TBKeyPathSearchController *searchController;
  15. @property (nonatomic, readonly ) UIView *promptView;
  16. @property (nonatomic, readwrite) UITableView *tableView;
  17. @property (nonatomic, readwrite) UISearchBar *searchBar;
  18. // .@property (nonatomic, readonly) void (^callback)();
  19. @end
  20. @implementation TBKeyPathViewController
  21. @dynamic navigationController;
  22. #pragma mark - Setup, view events
  23. - (void)loadView {
  24. self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  25. self.searchBar = [UISearchBar new];
  26. self.view = self.tableView;
  27. [self.searchBar sizeToFit];
  28. self.tableView.tableHeaderView = self.searchBar;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.title = @"Choose Hook";
  33. // Search controller stuff
  34. _searchController = [TBKeyPathSearchController delegate:self];
  35. _searchController.toolbar = [TBKeyPathToolbar toolbarWithHandler:^(NSString *buttonTitle) {
  36. [self.searchController didPressButton:buttonTitle insertInto:self.searchBar];
  37. }];
  38. // Search bar stuff
  39. self.searchBar.delegate = self.searchController;
  40. self.searchBar.placeholder = @"UIKit*.UIView.-setFrame:";
  41. self.searchBar.inputAccessoryView = self.searchController.toolbar;
  42. // Table view stuff
  43. self.tableView.rowHeight = UITableViewAutomaticDimension;
  44. // [self.tableView registerCell:[TBCodeFontCell class]];
  45. // Long press gesture for classes
  46. [self.tableView addGestureRecognizer:[UILongPressGestureRecognizer action:^(UIGestureRecognizer *gesture) {
  47. if (gesture.state == UIGestureRecognizerStateBegan) {
  48. NSIndexPath *ip = [self.tableView indexPathForRowAtPoint:[gesture locationInView:self.tableView]];
  49. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:ip];
  50. [self.searchController longPressedRect:cell.frame at:ip];
  51. }
  52. }]];
  53. }
  54. - (void)viewWillAppear:(BOOL)animated {
  55. [super viewWillAppear:animated];
  56. [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
  57. [self.searchBar becomeFirstResponder];
  58. }
  59. - (void)viewWillDisappear:(BOOL)animated {
  60. [super viewWillDisappear:animated];
  61. [self.searchBar resignFirstResponder];
  62. }
  63. #pragma mark Delegate stuff
  64. - (void)didSelectMethod:(FLEXMethod *)method {
  65. }
  66. #pragma mark Long press action
  67. - (NSString *)longPressItemSELPrefix { return @"tb_"; }
  68. - (void)didSelectSuperclass:(NSString *)title {
  69. [self.searchController didSelectSuperclass:title];
  70. }
  71. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
  72. return [@((char*)(void*)action) hasPrefix:self.longPressItemSELPrefix];
  73. }
  74. - (BOOL)canBecomeFirstResponder {
  75. return YES;
  76. }
  77. - (NSMethodSignature *)methodSignatureForSelector:(SEL)sel {
  78. if ([super methodSignatureForSelector:sel]) {
  79. return [super methodSignatureForSelector:sel];
  80. }
  81. return [super methodSignatureForSelector:@selector(didSelectSuperclass:)];
  82. }
  83. - (void)forwardInvocation:(NSInvocation *)invocation {
  84. NSString *title = NSStringFromSelector([invocation selector]);
  85. NSRange match = [title rangeOfString:self.longPressItemSELPrefix];
  86. if (match.location == 0) {
  87. [self didSelectSuperclass:[title substringFromIndex:3]];
  88. } else {
  89. [super forwardInvocation:invocation];
  90. }
  91. }
  92. @end