You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.5 KiB

  1. //
  2. // FLEXTableViewCell.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 4/17/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXTableViewCell.h"
  9. #import "FLEXUtility.h"
  10. #import "FLEXTableView.h"
  11. @interface UITableView (Internal)
  12. // Exists at least since iOS 5
  13. - (BOOL)_canPerformAction:(SEL)action forCell:(UITableViewCell *)cell sender:(id)sender;
  14. - (void)_performAction:(SEL)action forCell:(UITableViewCell *)cell sender:(id)sender;
  15. @end
  16. @interface UITableViewCell (Internal)
  17. // Exists at least since iOS 5
  18. @property (nonatomic, readonly) FLEXTableView *_tableView;
  19. @end
  20. @implementation FLEXTableViewCell
  21. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  22. {
  23. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  24. if (self) {
  25. UIFont *cellFont = [FLEXUtility defaultTableViewCellLabelFont];
  26. self.textLabel.font = cellFont;
  27. self.detailTextLabel.font = cellFont;
  28. self.detailTextLabel.textColor = [UIColor grayColor];
  29. }
  30. return self;
  31. }
  32. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  33. {
  34. return [self._tableView _canPerformAction:action forCell:self sender:sender];
  35. }
  36. /// We use this to allow our table view to allow its delegate
  37. /// to handle any action it chooses to support, without
  38. /// explicitly implementing the method ourselelves.
  39. ///
  40. /// Alternative considered: override respondsToSelector
  41. /// to return NO. I decided against this for simplicity's
  42. /// sake. I see this as "fixing" a poorly designed API.
  43. /// That approach would require lots of boilerplate to
  44. /// make the menu appear above this cell.
  45. - (void)forwardInvocation:(NSInvocation *)invocation
  46. {
  47. // Must be unretained to avoid over-releasing
  48. __unsafe_unretained id sender;
  49. [invocation getArgument:&sender atIndex:2];
  50. SEL action = invocation.selector;
  51. // [self._tableView _performAction:action forCell:[self retain] sender:[sender retain]];
  52. invocation.selector = @selector(_performAction:forCell:sender:);
  53. [invocation setArgument:&action atIndex:2];
  54. [invocation setArgument:(void *)&self atIndex:3];
  55. [invocation setArgument:(void *)&sender atIndex:4];
  56. [invocation invokeWithTarget:self._tableView];
  57. }
  58. - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
  59. {
  60. if ([self canPerformAction:selector withSender:nil]) {
  61. return [self._tableView methodSignatureForSelector:@selector(_performAction:forCell:sender:)];
  62. }
  63. return [super methodSignatureForSelector:selector];
  64. }
  65. @end