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