| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- //
- // JDViewController.m
- // kneet2
- //
- // Created by Created by Jason Lee on 10/1/15.
- // Copyright (c) 2015 ntels. All rights reserved.
- //
- #import "CustomTableView.h"
- #import "OptionPopOverViewController.h"
- #import "WYPopoverController.h"
- #import "JDViewController.h"
- @interface JDViewController () <WYPopoverControllerDelegate, UITableViewDataSource, UITableViewDelegate> {
- WYPopoverController *_poc;
- OptionPopOverViewController *_ovc;
- }
- @end
- #pragma mark - Class Definition
- @implementation JDViewController
- @synthesize mainView = _mainView;
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self initUIOnSuper];
- [self prepareViewDidLoadOnSuper];
- }
- - (void)initUIOnSuper {
- }
- - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
- tableView.dataSource = self;
- tableView.delegate = self;
-
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- tableView.backgroundColor = [UIColor clearColor];
-
- tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
- }
- - (void)prepareViewDidLoadOnSuper {
-
- }
- - (UIButton *)generateOptionButton {
-
- UIImage *image = [UIImage imageNamed:@"common_head_btn_more"];
- UIImage *imagePress = [UIImage imageNamed:@"common_head_btn_more_press"];
- CGRect btnFrame = CGRectMake(0, 0, image.size.width, image.size.height);
-
- UIButton *button = [[UIButton alloc] initWithFrame:btnFrame];
- button.tag = 9003;
-
- [button setImage:image forState:UIControlStateNormal];
- [button setImage:imagePress forState:UIControlStateHighlighted];
- [button addTarget:self action:@selector(toggleOptions:) forControlEvents:UIControlEventTouchUpInside];
-
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.rightBarButtonItem = item;
- return button;
- }
- - (void)toggleOptions:(id)sender {
- UIButton *btn = (UIButton *)sender;
-
- if (!_poc) {
-
- _ovc = (OptionPopOverViewController *)[CommonUtil
- instantiateViewControllerWithIdentifier:@"OptionPopOverViewController"
- storyboardName:@"Common"];
-
- _ovc.dataArray = _popooverOptionArray;
-
- _poc = [[WYPopoverController alloc] initWithContentViewController:_ovc];
- _poc.delegate = self;
-
- [_poc beginThemeUpdates];
-
- _poc.theme.usesRoundedArrow = NO;
-
- _poc.theme.arrowBase = 15;
- _poc.theme.arrowHeight = 8;
- _poc.theme.borderWidth = 0;
- _poc.theme.tintColor = [UIColor darkGrayColor];
- _poc.theme.outerStrokeColor = [UIColor darkGrayColor];
- _poc.theme.innerStrokeColor = [UIColor lightGrayColor];
-
- _poc.theme.innerCornerRadius = 0.0f;
- _poc.theme.outerCornerRadius = 0.0f;
- _poc.theme.minOuterCornerRadius = 0.0f;
-
- _poc.theme.fillTopColor = [UIColor lightGrayColor];
-
- [_poc endThemeUpdates];
-
-
- _ovc.poc = _poc;
- }
-
- // UIBarButtonItem *barButtonItem = self.navigationItem.rightBarButtonItem;
- // UIView *itemView = [barButtonItem valueForKey:@"view"];
- CGRect popRect = btn.bounds;
- popRect.origin.y = 20.0f;
-
- [_poc presentPopoverFromRect:popRect inView:btn
- permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:^{
- [_ovc.tableView reloadData];
- }];
-
- // [_poc presentPopoverFromRect:btn.bounds
- // inView:btn
- // permittedArrowDirections:WYPopoverArrowDirectionUp
- // animated:YES
- // options:WYPopoverAnimationOptionFadeWithScale];
- }
- - (void)resetOptions {
- _ovc = nil;
- _poc = nil;
- }
- - (void)dismissOptionPopOver:(void (^)(void))completion {
- [_poc dismissPopoverAnimated:YES completion:^{
- if (completion) {
- completion();
- }
- }];
- }
- #pragma mark - Main Logic
- #pragma mark - UITableView DataSource & Delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
-
- // Remove seperator inset
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- [cell setSeparatorInset:UIEdgeInsetsZero];
- }
-
- // Prevent the cell from inheriting the Table View's margin settings
- if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
- [cell setPreservesSuperviewLayoutMargins:NO];
- }
-
- // Explictly set your cell's layout margins
- if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- }
- #pragma mark - UI Events
- #pragma mark - MemoryWarning
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|