JDViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // JDViewController.m
  3. // kneet2
  4. //
  5. // Created by Created by Jason Lee on 10/1/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "CustomTableView.h"
  9. #import "OptionPopOverViewController.h"
  10. #import "WYPopoverController.h"
  11. #import "JDViewController.h"
  12. @interface JDViewController () <WYPopoverControllerDelegate, UITableViewDataSource, UITableViewDelegate> {
  13. WYPopoverController *_poc;
  14. OptionPopOverViewController *_ovc;
  15. }
  16. @end
  17. #pragma mark - Class Definition
  18. @implementation JDViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self initUIOnSuper];
  23. [self prepareViewDidLoadOnSuper];
  24. }
  25. - (void)initUIOnSuper {
  26. }
  27. - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
  28. tableView.dataSource = self;
  29. tableView.delegate = self;
  30. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  31. tableView.backgroundColor = [UIColor clearColor];
  32. tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  33. }
  34. - (void)prepareViewDidLoadOnSuper {
  35. }
  36. - (UIButton *)generateOptionButton {
  37. UIImage *image = [UIImage imageNamed:@"common_head_btn_more"];
  38. UIImage *imagePress = [UIImage imageNamed:@"common_head_btn_more_press"];
  39. CGRect btnFrame = CGRectMake(0, 0, image.size.width, image.size.height);
  40. UIButton *button = [[UIButton alloc] initWithFrame:btnFrame];
  41. button.tag = 9003;
  42. [button setImage:image forState:UIControlStateNormal];
  43. [button setImage:imagePress forState:UIControlStateHighlighted];
  44. [button addTarget:self action:@selector(toggleOptions:) forControlEvents:UIControlEventTouchUpInside];
  45. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
  46. self.navigationItem.rightBarButtonItem = item;
  47. return button;
  48. }
  49. - (void)toggleOptions:(id)sender {
  50. UIButton *btn = (UIButton *)sender;
  51. if (!_poc) {
  52. _ovc = (OptionPopOverViewController *)[CommonUtil
  53. instantiateViewControllerWithIdentifier:@"OptionPopOverViewController"
  54. storyboardName:@"Common"];
  55. _ovc.dataArray = _popooverOptionArray;
  56. _poc = [[WYPopoverController alloc] initWithContentViewController:_ovc];
  57. _poc.delegate = self;
  58. [_poc beginThemeUpdates];
  59. _poc.theme.usesRoundedArrow = NO;
  60. _poc.theme.arrowBase = 15;
  61. _poc.theme.arrowHeight = 8;
  62. _poc.theme.borderWidth = 0;
  63. _poc.theme.tintColor = [UIColor darkGrayColor];
  64. _poc.theme.outerStrokeColor = [UIColor darkGrayColor];
  65. _poc.theme.innerStrokeColor = [UIColor lightGrayColor];
  66. _poc.theme.innerCornerRadius = 0.0f;
  67. _poc.theme.outerCornerRadius = 0.0f;
  68. _poc.theme.minOuterCornerRadius = 0.0f;
  69. _poc.theme.fillTopColor = [UIColor lightGrayColor];
  70. [_poc endThemeUpdates];
  71. _ovc.poc = _poc;
  72. }
  73. // UIBarButtonItem *barButtonItem = self.navigationItem.rightBarButtonItem;
  74. // UIView *itemView = [barButtonItem valueForKey:@"view"];
  75. CGRect popRect = btn.bounds;
  76. popRect.origin.y = 20.0f;
  77. [_poc presentPopoverFromRect:popRect inView:btn
  78. permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:^{
  79. [_ovc.tableView reloadData];
  80. }];
  81. // [_poc presentPopoverFromRect:btn.bounds
  82. // inView:btn
  83. // permittedArrowDirections:WYPopoverArrowDirectionUp
  84. // animated:YES
  85. // options:WYPopoverAnimationOptionFadeWithScale];
  86. }
  87. - (void)resetOptions {
  88. _ovc = nil;
  89. _poc = nil;
  90. }
  91. - (void)dismissOptionPopOver:(void (^)(void))completion {
  92. [_poc dismissPopoverAnimated:YES completion:^{
  93. if (completion) {
  94. completion();
  95. }
  96. }];
  97. }
  98. #pragma mark - Main Logic
  99. #pragma mark - UITableView DataSource & Delegate
  100. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  101. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  102. }
  103. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  104. // Remove seperator inset
  105. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  106. [cell setSeparatorInset:UIEdgeInsetsZero];
  107. }
  108. // Prevent the cell from inheriting the Table View's margin settings
  109. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  110. [cell setPreservesSuperviewLayoutMargins:NO];
  111. }
  112. // Explictly set your cell's layout margins
  113. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  114. [cell setLayoutMargins:UIEdgeInsetsZero];
  115. }
  116. }
  117. #pragma mark - UI Events
  118. #pragma mark - MemoryWarning
  119. - (void)didReceiveMemoryWarning
  120. {
  121. [super didReceiveMemoryWarning];
  122. // Dispose of any resources that can be recreated.
  123. }
  124. @end