// // ViewController.m // FirstLink // // Created by mac on 14-8-25. // Copyright (c) 2014年 FirstLink. All rights reserved. // #import "FLViewController.h" #import "SchemaManager.h" #import #import "FirstLinkAppDelegate.h" #import "FLControllerHelper.h" #import "FKLoadingView.h" @interface FLViewController () @property (nonatomic, weak) id originalDelgate; @property (nonatomic, strong) UITableViewCell *noContentTipCell; @property (nonatomic, strong) FKLoadingView *loadingView; @end @implementation FLViewController @synthesize refreshControl = _refreshControl; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization self.edgesForExtendedLayout = NO; self.convertPopDelegate = YES; if([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { self.navigationController.navigationBar.translucent = NO; } } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. [self configLeftNaviItem]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [MobClick beginLogPageView:NSStringFromClass([self class])]; if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] && self.convertPopDelegate) { self.originalDelgate = self.navigationController.interactivePopGestureRecognizer.delegate; self.navigationController.interactivePopGestureRecognizer.delegate = self; } } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [MobClick endLogPageView:NSStringFromClass([self class])]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [MobClick endLogPageView:NSStringFromClass([self class])]; if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] && self.convertPopDelegate) { if (self.originalDelgate) { self.navigationController.interactivePopGestureRecognizer.delegate = self.originalDelgate; self.originalDelgate = nil; } } self.openURLPara = nil; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; NSArray *viewControllers = [FLControllerHelper currentControllers]; if (viewControllers.count <= 1) { [[FKPageRouterUtil sharedInstance] removePageRefers]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Refresh - (void)forceRefresh { } #pragma mark - RefreshControl - (void)initRefreshControlWithTableView:(UITableView *)tableView { self.refreshControl = [[FKRefreshControl alloc] initWithScrollView:tableView delegate:self]; self.refreshControl.autoRefreshBottom = YES; self.refreshControl.enableInsetBottom = 0; self.refreshControl.topEnabled = YES; self.refreshControl.bottomEnabled = YES; } - (void)finishLoadingData { if (self.refreshControl.refreshingDirection==RefreshingDirectionTop) { [self.refreshControl finishRefreshingDirection:RefreshDirectionTop]; } else if (self.refreshControl.refreshingDirection==RefreshingDirectionBottom) { [self.refreshControl finishRefreshingDirection:RefreshDirectionBottom]; } } #pragma mark - HUD - (MBProgressHUD*)hudView { if (!_hudView) { _hudView = [[MBProgressHUD alloc] initWithView:self.view]; _hudView.color = [UIColor clearColor]; _hudView.mode = MBProgressHUDModeCustomView; _hudView.customView = self.loadingView; [self.view addSubview:_hudView]; } [self.loadingView startAnimation]; [self.view bringSubviewToFront:_hudView]; return _hudView; } - (FKLoadingView *)loadingView { if (!_loadingView) { _loadingView = [FKLoadingView new]; _loadingView.frame = CGRectMake(0, 0, 80, 80); } return _loadingView; } #pragma mark - Status View - (FKStatusTipView*)statusView { if (!_statusView) { _statusView = [[FKStatusTipView alloc] init]; } return _statusView; } - (FLEmptyFooter*)emptyFooterView { if (!_emptyFooterView) { _emptyFooterView = [[FLEmptyFooter alloc] initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, [FLEmptyFooter height])]; _emptyFooterView.textLabel.text = @"休息一下吧,所有商品已看完了"; } return _emptyFooterView; } - (void)showSystemErrorTipInView:(UIView*)view { self.statusView.statusImageView.image = [UIImage imageNamed:@"StatusSystemError"]; self.statusView.statusLabel.text = SystemErrorTip; self.statusView.actionButton.hidden = NO; self.statusView.actionButton.layer.borderWidth = 0; self.statusView.actionButton.layer.cornerRadius = 0; [self.statusView.actionButton setBackgroundImage:[UIImage imageNamed:@"StatusSystemButtonIcon"] forState:UIControlStateNormal]; self.statusView.backgroundColor = UIColorFromRGB(0xf4f4f4); self.statusView.frame = view.bounds; [view addSubview:self.statusView]; } - (void)showStatusTipInView:(UIView *)view image:(UIImage *)image title:(NSString *)title { self.statusView.statusImageView.image = image; self.statusView.statusLabel.text = title; self.statusView.backgroundColor = UIColorFromRGB(0xf4f4f4); self.statusView.frame = CGRectMake(0, 0, CGRectGetWidth(view.frame), CGRectGetHeight(view.frame)); [view addSubview:self.statusView]; } #pragma mark - NaviBar - (void)configLeftNaviItem { self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fk_common_back"] style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftNaviItem)]; } - (void)clickLeftNaviItem { if (self.navigationController){ [self.navigationController popViewControllerAnimated:YES]; } } - (void)hideDefaultLeftNaviItem { self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage new] style:UIBarButtonItemStylePlain target:nil action:nil]; } - (void)hideHud:(BOOL)animated { [self.hudView hide:animated]; [self.hudView removeFromSuperview]; self.hudView = nil; } #pragma mark - Login Action - (void)showLoginActionMenu { JGActionSheetSection *section = [JGActionSheetSection sectionWithTitle:nil message:@"是否登录?" buttonTitles:@[@"登录", @"取消"] buttonStyle:JGActionSheetButtonStyleDefault]; section.tintColor = UIColorFromRGB(0x999999); JGActionSheet *actionSheet = [JGActionSheet actionSheetWithSections:@[section]]; UIButton *button = section.buttons.firstObject; [button setTitleColor:UIColorFromRGB(0xff624a) forState:UIControlStateNormal]; button.layer.borderWidth = 0; button = section.buttons[1]; [button setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal]; button.layer.borderWidth = 0; actionSheet.delegate = self; actionSheet.insets = UIEdgeInsetsMake(20.0f, 0.0f, IS_IPHONE_X ? 34.0f : 0.0f, 0.0f); if (IS_IPHONE_X) { UIView *view = [UIView new]; view.backgroundColor = [UIColor whiteColor]; [actionSheet addSubview:view]; [view mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.equalTo(actionSheet); make.height.mas_equalTo(34); }]; } WeakSelf(weakSelf); actionSheet.outsidePressBlock = ^(JGActionSheet *sheet) { [sheet dismissAnimated:YES]; [weakSelf dismissMenuWithNotLogin]; }; [actionSheet setButtonPressedBlock:^(JGActionSheet *sheet, NSIndexPath *indexPath) { [sheet dismissAnimated:YES]; if (indexPath.row == 1) { [weakSelf dismissMenuWithNotLogin]; } }]; FirstLinkAppDelegate *delegate = (FirstLinkAppDelegate *)[[UIApplication sharedApplication] delegate]; [actionSheet showInView:delegate.window animated:YES]; } - (void)actionSheet:(JGActionSheet *)actionSheet pressedButtonAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { [FLControllerHelper presentLoginViewController]; } } - (void)dismissMenuWithNotLogin { } @end