JDViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. #import "HomeMemberViewController.h"
  13. #import "MorePopOverViewController.h"
  14. @interface JDViewController () <WYPopoverControllerDelegate, UITableViewDataSource, UITableViewDelegate> {
  15. WYPopoverController *_poc;
  16. OptionPopOverViewController *_ovc;
  17. MorePopOverViewController *_MoreVc;
  18. }
  19. @end
  20. #pragma mark - Class Definition
  21. @implementation JDViewController
  22. @synthesize mainView = _mainView;
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self initUIOnSuper];
  27. [self prepareViewDidLoadOnSuper];
  28. }
  29. - (void)initUIOnSuper {
  30. }
  31. - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
  32. tableView.dataSource = self;
  33. tableView.delegate = self;
  34. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  35. tableView.backgroundColor = [UIColor clearColor];
  36. // tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 30.0f)]; //this call table events;
  37. }
  38. - (void)prepareViewDidLoadOnSuper {
  39. }
  40. - (UIButton *)generateOptionButton {
  41. UIImage *image = [UIImage imageNamed:@"common_head_btn_more"];
  42. UIImage *imagePress = [UIImage imageNamed:@"common_head_btn_more_press"];
  43. CGRect btnFrame = CGRectMake(0, 0, image.size.width, image.size.height);
  44. UIButton *button = [[UIButton alloc] initWithFrame:btnFrame];
  45. button.tag = 9003;
  46. [button setImage:image forState:UIControlStateNormal];
  47. [button setImage:imagePress forState:UIControlStateHighlighted];
  48. [button addTarget:self action:@selector(toggleOptions:) forControlEvents:UIControlEventTouchUpInside];
  49. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
  50. self.navigationItem.rightBarButtonItem = item;
  51. return button;
  52. }
  53. - (void)returnMoreId:(id)moreButtonId{
  54. NSLog(@"JDViewMoreButton : %@",moreButtonId);
  55. }
  56. - (void)toggleOptionsWithArray:(id)sender btnArray:(NSMutableArray *)btnArray
  57. {
  58. UIButton *moreBtn = (UIButton *)sender;
  59. // UIStoryboard *storyboard =[UIStoryboard storyboardWithName:@"Common" bundle:nil];
  60. // MorePopOverViewController *ctl =[storyboard instantiateViewControllerWithIdentifier:@"MorePopOverViewController"];
  61. // ctl.moreDelegate = self;
  62. // NSLog(@"MoreDelegate : %@",ctl.moreDelegate);
  63. if (!_poc){
  64. _MoreVc = (MorePopOverViewController *)[CommonUtil
  65. instantiateViewControllerWithIdentifier:@"MorePopOverViewController"
  66. storyboardName:@"Common"];
  67. _poc = [[WYPopoverController alloc] initWithContentViewController:_MoreVc];
  68. _poc.delegate = self;
  69. [_poc beginThemeUpdates];
  70. _poc.popoverLayoutMargins = UIEdgeInsetsMake(0, 0, 0, 0);
  71. _poc.theme.arrowHeight = 0;
  72. _poc.theme.borderWidth = 0;
  73. _poc.theme.innerCornerRadius = 0.0f;
  74. _poc.theme.outerCornerRadius = 0.0f;
  75. _poc.theme.minOuterCornerRadius = 0.0f;
  76. [_poc endThemeUpdates];
  77. [_MoreVc popButtonSet:btnArray];
  78. // [_MoreVc popButtonSet:firstBtn secondType:secondBtn thirdType:thirdBtn fourthType:fourthBtn];
  79. _MoreVc.poc = _poc;
  80. }
  81. CGRect popRect = moreBtn.bounds;
  82. [_poc presentPopoverFromRect:popRect
  83. inView:moreBtn
  84. permittedArrowDirections:WYPopoverArrowDirectionUp
  85. animated:YES
  86. options:WYPopoverAnimationOptionFadeWithScale];
  87. }
  88. - (void)toggleOptions:(id)sender {
  89. UIButton *btn = (UIButton *)sender;
  90. if (!_poc) {
  91. _ovc = (OptionPopOverViewController *)[CommonUtil
  92. instantiateViewControllerWithIdentifier:@"OptionPopOverViewController"
  93. storyboardName:@"Common"];
  94. _ovc.dataArray = _popooverOptionArray;
  95. _poc = [[WYPopoverController alloc] initWithContentViewController:_ovc];
  96. _poc.delegate = self;
  97. [_poc beginThemeUpdates];
  98. _poc.popoverLayoutMargins = UIEdgeInsetsMake(10, 0, 0, 0);
  99. _poc.theme.arrowHeight = 0;
  100. _poc.theme.borderWidth = 0;
  101. _poc.theme.usesRoundedArrow = NO;
  102. _poc.theme.arrowBase = 15;
  103. _poc.theme.arrowHeight = 8;
  104. _poc.theme.borderWidth = 0;
  105. // _poc.theme.tintColor = [UIColor darkGrayColor];
  106. _poc.theme.outerStrokeColor = kUILineColor2;
  107. _poc.theme.innerStrokeColor = kUILineColor2;
  108. _poc.theme.innerCornerRadius = 0.0f;
  109. _poc.theme.outerCornerRadius = 0.0f;
  110. _poc.theme.minOuterCornerRadius = 0.0f;
  111. [_poc endThemeUpdates];
  112. // [_MoreVc popButtonSet:none secondType:none thirdType:del fourthType:reload];
  113. _ovc.poc = _poc;
  114. }
  115. // UIBarButtonItem *barButtonItem = self.navigationItem.rightBarButtonItem;
  116. // UIView *itemView = [barButtonItem valueForKey:@"view"];
  117. CGRect popRect = btn.bounds;
  118. // popRect.origin.y = 0.0f;
  119. // [_poc presentPopoverFromRect:popRect inView:btn
  120. // permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:nil];
  121. [_poc presentPopoverFromRect:popRect
  122. inView:btn
  123. permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp
  124. animated:YES
  125. options:WYPopoverAnimationOptionFadeWithScale];
  126. // [_poc presentPopoverFromRect:popRect inView:btn
  127. // permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:^{
  128. // [_ovc.tableView reloadData];
  129. // }];
  130. // [_poc presentPopoverFromRect:btn.bounds
  131. // inView:btn
  132. // permittedArrowDirections:WYPopoverArrowDirectionUp
  133. // animated:YES
  134. // options:WYPopoverAnimationOptionFadeWithScale];
  135. }
  136. - (void)resetOptions {
  137. _ovc = nil;
  138. _poc = nil;
  139. }
  140. - (void)dismissOptionPopOver:(void (^)(void))completion {
  141. [_poc dismissPopoverAnimated:YES completion:^{
  142. if (completion) {
  143. completion();
  144. }
  145. }];
  146. }
  147. #pragma mark - Main Logic
  148. #pragma mark - UITableView DataSource & Delegate
  149. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  150. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  151. }
  152. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  153. // Remove seperator inset
  154. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  155. [cell setSeparatorInset:UIEdgeInsetsZero];
  156. }
  157. // Prevent the cell from inheriting the Table View's margin settings
  158. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  159. [cell setPreservesSuperviewLayoutMargins:NO];
  160. }
  161. // Explictly set your cell's layout margins
  162. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  163. [cell setLayoutMargins:UIEdgeInsetsZero];
  164. }
  165. }
  166. #pragma mark - UI Events
  167. #pragma mark - MemoryWarning
  168. - (void)didReceiveMemoryWarning
  169. {
  170. [super didReceiveMemoryWarning];
  171. // Dispose of any resources that can be recreated.
  172. }
  173. @end