Commit 217e9399 authored by 翟国钧's avatar 翟国钧

Merge branch 'wy/no-hud' into 'master'

Wy/no hud

将hud部分代码移到GMHud中;将emptyView移动到GMKit中;添加GMBaseCollectionController

See merge request !4
parents 0e6a1c80 d3dbd2c4
use_frameworks! use_frameworks!
inhibit_all_warnings!
platform :ios, '8.0' platform :ios, '8.0'
#open source #open source
source 'https://github.com/CocoaPods/Specs.git' source 'https://github.com/CocoaPods/Specs.git'
...@@ -20,9 +21,6 @@ post_install do |installer| ...@@ -20,9 +21,6 @@ post_install do |installer|
installer.pods_project.targets.each do |target| installer.pods_project.targets.each do |target|
target.build_configurations.each do |config| target.build_configurations.each do |config|
# 指定使用swift 2.3版本
config.build_settings['SWIFT_VERSION'] = '2.3'
end end
end end
end end
......
...@@ -14,18 +14,57 @@ PODS: ...@@ -14,18 +14,57 @@ PODS:
- AFNetworking/Serialization (3.1.0) - AFNetworking/Serialization (3.1.0)
- AFNetworking/UIKit (3.1.0): - AFNetworking/UIKit (3.1.0):
- AFNetworking/NSURLSession - AFNetworking/NSURLSession
- Base64nl (1.2)
- GMBase (0.0.25): - GMBase (0.0.25):
- GMHud
- GMKit
- GMNetService - GMNetService
- GMPhobos - GMPhobos
- GMRefresh - GMRefresh
- JSONModel (= 1.2.0) - JSONModel (= 1.2.0)
- Masonry (= 1.0.1) - Masonry (= 1.0.1)
- MBProgressHUD (= 0.9.2) - MBProgressHUD
- UITableView+FDTemplateLayoutCell (= 1.4) - UITableView+FDTemplateLayoutCell (= 1.4)
- GMCache (0.1.1): - GMCache (0.1.1):
- TMCache (~> 2.1.0) - TMCache (~> 2.1.0)
- GMFoundation (0.0.4):
- Base64nl (= 1.2)
- GMHud (0.1.1):
- MBProgressHUD (= 0.9.2)
- GMKit (0.7.19):
- GMFoundation
- GMKit/Category (= 0.7.19)
- GMKit/FDFullscreenPopGesture (= 0.7.19)
- GMKit/Kit (= 0.7.19)
- GMKit/Protocol (= 0.7.19)
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMKit/Category (0.7.19):
- GMFoundation
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMKit/FDFullscreenPopGesture (0.7.19):
- GMFoundation
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMKit/Kit (0.7.19):
- GMFoundation
- GMKit/Category (= 0.7.19)
- GMKit/Protocol (= 0.7.19)
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMKit/Protocol (0.7.19):
- GMFoundation
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMNetService (0.1.7): - GMNetService (0.1.7):
- AFNetworking (= 3.1.0) - AFNetworking (= 3.1.0)
- GMOCConstant (0.0.3)
- GMPhobos (0.3.3): - GMPhobos (0.3.3):
- GMCache (~> 0.1.1) - GMCache (~> 0.1.1)
- GMRefresh (0.1.5): - GMRefresh (0.1.5):
...@@ -34,6 +73,9 @@ PODS: ...@@ -34,6 +73,9 @@ PODS:
- Masonry (1.0.1) - Masonry (1.0.1)
- MBProgressHUD (0.9.2) - MBProgressHUD (0.9.2)
- MJRefresh (3.1.12) - MJRefresh (3.1.12)
- SDWebImage (3.7.6):
- SDWebImage/Core (= 3.7.6)
- SDWebImage/Core (3.7.6)
- TMCache (2.1.0) - TMCache (2.1.0)
- UITableView+FDTemplateLayoutCell (1.4) - UITableView+FDTemplateLayoutCell (1.4)
...@@ -46,8 +88,14 @@ EXTERNAL SOURCES: ...@@ -46,8 +88,14 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67 AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
GMBase: a521e134341ed3d5f3b9a0d2315bc0f6b5f681b8 Base64nl: a497bdcd1c01ea793d36b399016195a8713c0e95
GMBase: fbf9da56b66675368d536b402f06502386e582d7
GMCache: 73855b613b9d7e34f4f37ad425e8b8153b760c04 GMCache: 73855b613b9d7e34f4f37ad425e8b8153b760c04
GMFoundation: 395f1083c40aa38e9fb031726991dbc20247e2f9
GMHud: 67c24abb83777c61e43741d4a803f7b6d8ad4e1e
GMKit: c23a05b5505b5f72b6c34686fa9a56a5ab6efc6f
GMNetService: 59825077fcb1b7d332023e9ad511239dc70a8879
GMOCConstant: 39371248b4d8d54929391bfcd2c5883776436c4b
GMNetService: 1accbf087c6047e38c0b3a7201e9a3f1789c1438 GMNetService: 1accbf087c6047e38c0b3a7201e9a3f1789c1438
GMPhobos: c32984b4902cb6dd931a53d647931c2d4fc00a12 GMPhobos: c32984b4902cb6dd931a53d647931c2d4fc00a12
GMRefresh: b9f0674b9b14c533ec2586147ea40a833ed5867d GMRefresh: b9f0674b9b14c533ec2586147ea40a833ed5867d
...@@ -55,9 +103,10 @@ SPEC CHECKSUMS: ...@@ -55,9 +103,10 @@ SPEC CHECKSUMS:
Masonry: a1a931a0d08870ed8ae415a2ea5ea68ebcac77df Masonry: a1a931a0d08870ed8ae415a2ea5ea68ebcac77df
MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1 MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1
MJRefresh: b96cdb21c4aa75a7b07654311ab2f315c497e806 MJRefresh: b96cdb21c4aa75a7b07654311ab2f315c497e806
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
UITableView+FDTemplateLayoutCell: 234e1582bcc4e18461af91155123bb96538ed030 UITableView+FDTemplateLayoutCell: 234e1582bcc4e18461af91155123bb96538ed030
PODFILE CHECKSUM: 88292ff9a97184fd102b59fb11ccfaf5b4dfbe90 PODFILE CHECKSUM: 0c80e9302d494ed154da93823382c933df985f69
COCOAPODS: 1.2.1 COCOAPODS: 1.2.1
...@@ -14,7 +14,9 @@ Pod::Spec.new do |s| ...@@ -14,7 +14,9 @@ Pod::Spec.new do |s|
s.dependency 'JSONModel', '1.2.0' s.dependency 'JSONModel', '1.2.0'
s.dependency 'UITableView+FDTemplateLayoutCell', '1.4' s.dependency 'UITableView+FDTemplateLayoutCell', '1.4'
s.dependency 'GMNetService' s.dependency 'GMNetService'
s.dependency 'MBProgressHUD', '0.9.2' s.dependency 'MBProgressHUD'
s.dependency 'Masonry' , '1.0.1' s.dependency 'Masonry' , '1.0.1'
s.dependency 'GMPhobos' s.dependency 'GMPhobos'
s.dependency 'GMHud'
s.dependency 'GMKit'
end end
//
// GMBase.h
// Pods
//
// Created by wangyang on 16/7/11.
//
//
#ifndef GMBase_h
#define GMBase_h
#import "GMBase.h"
#import "GMObject.h"
#import "OCEmptyView.h"
#import "OCNavigatioinBar.h"
#import "UIViewController+HUD.h"
#import "WMBaseListViewController.h"
#import "WMBaseViewController.h"
#import "WMFetchDataViewModel.h"
#import "WMNavigationController.h"
#import "WMViewModel.h"
#endif /* GMBase_h */
//
// OCEmptyView.h
// Gengmei
//
// Created by wangyang on 16/7/9.
// Copyright © 2016年 更美互动信息科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface OCRedGradientButton : UIButton
@end
typedef NS_ENUM(NSUInteger, OCEmptyViewType) {
OCEmptyViewTypeEmpty,
OCEmptyViewTypeException
};
@protocol OCEmptyViewDelegate <NSObject>
- (void)emptyViewDidClickReload;
@end
@interface OCEmptyView : UIView
@property (nonatomic, strong) UIImageView *tipIcon;
@property (nonatomic, strong) UILabel *tipLabel;
@property (nonatomic, strong) OCRedGradientButton *tipButton;
@property (nonatomic, assign) OCEmptyViewType type;
@property (nonatomic, weak) id<OCEmptyViewDelegate> delegate;
@property (nonatomic, copy) NSString *tipImage;
@property (nonatomic, copy) NSString *tipText;
@end
...@@ -35,6 +35,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -35,6 +35,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, readonly) OCNavigatioinBarButton *rightButton; @property (nonatomic, strong, readonly) OCNavigatioinBarButton *rightButton;
@property (nonatomic, strong, readonly) OCNavigatioinBarButton *nearRightButton; @property (nonatomic, strong, readonly) OCNavigatioinBarButton *nearRightButton;
/**
leftIcon 有默认值:back
*/
@property (nonatomic, copy, nullable) NSString *leftIcon; @property (nonatomic, copy, nullable) NSString *leftIcon;
@property (nonatomic, copy, nullable) NSString *rightIcon; @property (nonatomic, copy, nullable) NSString *rightIcon;
@property (nonatomic, copy, nullable) NSString *nearRightIcon; @property (nonatomic, copy, nullable) NSString *nearRightIcon;
......
//
// UIViewController+HUD.h
// Pods
//
// Created by wangyang on 16/7/11.
//
//
#import <UIKit/UIKit.h>
#import <MBProgressHUD/MBProgressHUD.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIViewController (HUD)
/**
* @brief 显示加载动画
* @param text 加载动画文字
*/
- (void)showLoading:(nullable NSString *)text;
/**
* @brief 显示隐藏加载
* @param text 警告文字
*/
- (void)hideLoading;
/**
* @brief 显示完成信息,1秒后消失
* @param text 文字
*/
- (void)showComplete:(NSString *)text;
/**
* @brief 显示警告或错误信息,1秒后消失
* @param text 警告文字
*/
- (void)showWarning:(NSString *)text;
/**
* @brief toast
*
* @param text 仅显示文字提示
*/
- (void)toast:(NSString *)text;
- (void)toastInView:(NSString *)text;
@end
NS_ASSUME_NONNULL_END
\ No newline at end of file
//
// UIViewController+HUD.m
// Pods
//
// Created by wangyang on 16/7/11.
//
//
#import "UIViewController+HUD.h"
#import <objc/runtime.h>
@interface UIViewController (HUD)
@property (nonatomic, strong) MBProgressHUD *hud;
@end
@implementation UIViewController (HUD)
- (MBProgressHUD *)hud {
return objc_getAssociatedObject(self, @selector(hud));
}
- (void)setHud:(MBProgressHUD *)hud {
objc_setAssociatedObject(self, @selector(hud), hud, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (NSTimeInterval)timeForHUDString:(NSString *)string {
NSInteger count = string.length;
if (count < 8) {
return 1.0;
}else if (count >= 8 && count < 15) {
return 2;
} else if (count >= 15 && count < 25) {
return 3;
} else {
return 4;
}
}
- (void)showComplete:(NSString *)text
{
[self hideLoading];
self.hud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.hud];
self.hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ToastFinish"]];
self.hud.mode = MBProgressHUDModeCustomView;
self.hud.removeFromSuperViewOnHide = YES;
self.hud.delegate = self;
if (text!=nil && text.length>20) {
self.hud.detailsLabelText = text;
}else{
self.hud.labelText = text;
}
[self.hud show:YES];
NSTimeInterval timeInterval = [self timeForHUDString:text];
[self.hud hide:YES afterDelay:timeInterval];
}
- (void)showWarning:(NSString *)text
{
[self hideLoading];
self.hud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.hud];
self.hud.removeFromSuperViewOnHide = YES;
self.hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ToastWarn"]];
// Set custom view mode
self.hud.mode = MBProgressHUDModeCustomView;
self.hud.delegate = self;
if (text!=nil && text.length>20) {
self.hud.detailsLabelText = text;
}else{
self.hud.labelText = text;
}
[self.hud show:YES];
NSTimeInterval timeInterval = [self timeForHUDString:text];
[self.hud hide:YES afterDelay:timeInterval];
}
- (void)showLoading:(NSString *)text
{
[self hideLoading];
self.hud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.hud];
self.hud.removeFromSuperViewOnHide = YES;
self.hud.mode = MBProgressHUDModeIndeterminate;
self.hud.delegate = self;
self.hud.labelText = text;
[self.hud show:YES];
UIButton *button = [[self valueForKey:@"navigationBar"] valueForKey:@"rightButton"];
button.enabled = NO;
}
- (void)toast:(NSString *)text{
[self hideLoading];
if (text.length == 0) {
return;
}
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
hud.mode = MBProgressHUDModeText;
hud.userInteractionEnabled = YES;
if (text!=nil && text.length>18) {
hud.detailsLabelText = text;
}else{
hud.labelText = text;
}
hud.margin = 10.f;
hud.removeFromSuperViewOnHide = YES;
NSTimeInterval timeInterval = [self timeForHUDString:text];
[hud hide:YES afterDelay:timeInterval];
}
- (void)toastInView:(NSString *)text{
if (text.length == 0) {
return;
}
[self hideLoading];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.userInteractionEnabled = YES;
if (text!=nil && text.length>18) {
hud.detailsLabelText = text;
}else{
hud.labelText = text;
}
hud.margin = 10.f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:1.0];
}
- (void)hideLoading
{
[self.hud hide:YES];
UIButton *button = [[self valueForKey:@"navigationBar"] valueForKey:@"rightButton"];
button.enabled = YES;
}
@end
//
// WMBaseCollectionController.h
// Gengmei
//
// Created by wangyang on 9/2/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "WMBaseViewController.h"
#import "WMFetchDataViewModel.h"
@interface WMBaseCollectionController : WMBaseViewController <UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>{
BOOL _needHeaderRefresh;
BOOL _needFooterRefresh;
WMFetchDataViewModel *_viewModel;
UICollectionView *_collectionView;
UICollectionViewLayout *_collectionViewLayout;
}
@property (nonatomic, strong) WMFetchDataViewModel *viewModel;
/** @brief 控制当前VC的viewmodel是不是立即请求网络 **/
@property (nonatomic , assign) BOOL immediateLoad;
/**
* @brief 默认大小是self.view.bounds
*/
@property (nonatomic, strong) UICollectionView *collectionView;
/**
* @brief 默认返回一个 flowLayout
@code
minimumLineSpacing = 0;
minimumInteritemSpacing = 0;
itemSize = CGSizeMake(50, 50);
@endcode
详见具体实现
*/
@property (nonatomic, strong) UICollectionViewLayout *collectionViewLayout;
- (void)updateOtherUIData __attribute__((objc_requires_super));
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context __attribute__((objc_requires_super));
- (void)refreshList;
- (void)headerRereshing;
- (void)footerRereshing;
- (void)hideNavigationBar;
- (void)hideEmptyView;
- (NSString *)getEmptyText;
@end
//
// WMBaseCollectionController.m
// Gengmei
//
// Created by wangyang on 9/2/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "WMBaseCollectionController.h"
#import <GMRefresh/GMRefreshFooter.h>
#import <GMRefresh/GMRefreshHeader.h>
#import <Masonry/Masonry.h>
@import GMHud;
@interface WMBaseCollectionController ()
@end
@implementation WMBaseCollectionController
@synthesize viewModel = _viewModel;
@synthesize collectionView = _collectionView;
@synthesize collectionViewLayout = _collectionViewLayout;
- (void)initController{
[super initController];
self.viewModel = [[WMFetchDataViewModel alloc] init];
_needHeaderRefresh = YES;
_needFooterRefresh = YES;
_immediateLoad = YES;
}
- (void)viewDidLoad{
[super viewDidLoad];
[self addKVO];
[self.view addSubview:self.collectionView];
[_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(64, 0, 0, 0));
}];
__weak __typeof(self)weakSelf = self;
if (_needHeaderRefresh) {
_collectionView.mj_header = [GMRefreshHeader headerWithRefreshingBlock:^{
[weakSelf headerRereshing];
}];
}
if (_needFooterRefresh) {
_collectionView.mj_footer = [GMRefreshFooter footerWithRefreshingBlock:^{
[weakSelf footerRereshing];
}];
}
//获取数据
if (_immediateLoad) {
[self loadRemoteData];
}
}
- (void)hideNavigationBar {
self.navigationBar.hidden = YES;
[_collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
}];
}
- (void)addKVO
{
[self.viewModel addObserver:self forKeyPath:@"fetchDataSuccess" options:NSKeyValueObservingOptionNew context:NULL];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if ([keyPath isEqualToString:@"fetchDataSuccess"] && object == self.viewModel) {
[self hideLoading];
_collectionView.hidden = NO;
if ([[_viewModel fetchDataSuccess] boolValue]) {
if ([[self.viewModel dataArray] count] == 0 && [self.viewModel fetchDataNilMsg]) {
[self showEmptyView:GMEmptyViewTypeEmpty];
} else {
[self hideEmptyView];
}
}else{
[self showEmptyView:GMEmptyViewTypeException];
}
// 调用reloadData,并不会立即执行,而是下更新周期来了之后才可以。
// 将 endRefreshing 与 endRefreshing 放到后面的好处就是此时可以利用 updateOtherUIData 做点额外的事。比如判断mj_header.isRefreshing
[self updateOtherUIData];
if (_collectionView) {
[_collectionView reloadData];
[_collectionView.mj_header endRefreshing];
[_collectionView.mj_footer endRefreshing];
}
}
}
- (void)dealloc{
[self removeKVO];
if (self.isViewLoaded) {
[self.viewModel removeObserver:self forKeyPath:@"fetchDataSuccess"];
}
}
- (void)removeKVO{
}
/**
* @brief 下拉刷新
*/
- (void)headerRereshing
{
[self.viewModel handleHeaderRefreshing];
}
/**
* @brief 上拉加载更多
*/
- (void)footerRereshing
{
[self.viewModel handleFooterRereshing];
}
- (void)updateOtherUIData{
// 如果 contentSize 高没有 _collectionView.bounds.size.height 这个大,就强制设置一下,这样 collectionView 还能下拉滑动,以保证上拉、下拉正常使用
if (_collectionView.contentSize.height <= _collectionView.bounds.size.height) {
_collectionView.contentSize = CGSizeMake(_collectionView.bounds.size.width, _collectionView.bounds.size.height);
}
}
- (void)refreshList{
[self.viewModel setStartNum:0];
[[self.viewModel dataArray] removeAllObjects];
[_collectionView reloadData];
[self loadRemoteData];
}
- (void)loadRemoteData {
[self showLoading:nil];
[self.viewModel fetchRemoteData];
}
- (void)didMoveToParentViewController:(UIViewController *)parent {
[super didMoveToParentViewController:parent];
if (parent != nil && ![parent isKindOfClass:[UINavigationController class]]) {
[_collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0));
}];
}
}
#pragma mark - UICollectionViewDelegate and UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.viewModel.dataArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
return nil;
}
#pragma mark - Setter and Getter
- (UICollectionView *)collectionView{
if (!_collectionView) {
_collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.collectionViewLayout];
_collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.delegate = self;
_collectionView.alwaysBounceVertical = YES;
_collectionView.dataSource = self;
_collectionView.hidden = YES;
}
return _collectionView;
}
- (UICollectionViewLayout *)collectionViewLayout{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 3;
layout.minimumInteritemSpacing = 3;
layout.itemSize = CGSizeMake(50, 50);
_collectionViewLayout = layout;
return _collectionViewLayout;
}
#pragma mark - OCEmptyViewDelegate
- (void)emptyViewDidClickReload{
[self loadRemoteData];
}
- (NSString *)getEmptyText{
if (self.viewModel.message.length > 0) {
return self.viewModel.message;
}
return @"";
}
@end
...@@ -8,10 +8,9 @@ ...@@ -8,10 +8,9 @@
#import "WMBaseViewController.h" #import "WMBaseViewController.h"
#import <UITableView_FDTemplateLayoutCell/UITableView+FDTemplateLayoutCell.h> #import <UITableView_FDTemplateLayoutCell/UITableView+FDTemplateLayoutCell.h>
#import "OCEmptyView.h"
#import "WMFetchDataViewModel.h" #import "WMFetchDataViewModel.h"
@interface WMBaseListViewController : WMBaseViewController<UITableViewDelegate,UITableViewDataSource, OCEmptyViewDelegate> @interface WMBaseListViewController : WMBaseViewController<UITableViewDelegate,UITableViewDataSource>
{ {
UITableView *_table; UITableView *_table;
...@@ -35,7 +34,7 @@ ...@@ -35,7 +34,7 @@
/** @brief viewModel*/ /** @brief viewModel*/
@property (nonatomic,strong) WMFetchDataViewModel *viewModel; @property (nonatomic,strong) WMFetchDataViewModel *viewModel;
@property (nonatomic, strong) UITableView *table; @property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) OCEmptyView *emptyView;
/** @brief 控制当前VC的viewmodel是不是立即请求网络 **/ /** @brief 控制当前VC的viewmodel是不是立即请求网络 **/
@property (nonatomic , assign) BOOL immediateLoad; @property (nonatomic , assign) BOOL immediateLoad;
...@@ -77,16 +76,4 @@ ...@@ -77,16 +76,4 @@
* @since 6.0.0 * @since 6.0.0
*/ */
- (void)hideNavigationBar; - (void)hideNavigationBar;
- (void)hideEmptyView;
/*!
* @author zhaiguojun, 16-06-28
*
* @brief 给子类设置空view的文案
*
* @param text
*
* @since 6.1.0
*/
- (NSString *)getEmptyText;
@end @end
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import <GMRefresh/GMRefreshFooter.h> #import <GMRefresh/GMRefreshFooter.h>
#import <GMRefresh/GMRefreshHeader.h> #import <GMRefresh/GMRefreshHeader.h>
#import <Masonry/Masonry.h> #import <Masonry/Masonry.h>
@import GMHud;
@interface WMBaseListViewController () @interface WMBaseListViewController ()
...@@ -56,21 +57,6 @@ ...@@ -56,21 +57,6 @@
make.bottom.mas_equalTo(0); make.bottom.mas_equalTo(0);
}]; }];
// baseList的EmptyView
_emptyView = [[OCEmptyView alloc] initWithFrame:CGRectZero];
_emptyView.hidden = YES;
if([self getEmptyText].length > 0){
_emptyView.tipText = [self getEmptyText];
}
_emptyView.delegate = self;
[self.view addSubview:_emptyView];
[_emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.top.mas_equalTo(0);
make.bottom.mas_equalTo(0);
}];
__weak __typeof(self)weakSelf = self; __weak __typeof(self)weakSelf = self;
if (_needHeaderRefresh) { if (_needHeaderRefresh) {
_table.mj_header = [GMRefreshHeader headerWithRefreshingBlock:^{ _table.mj_header = [GMRefreshHeader headerWithRefreshingBlock:^{
...@@ -187,12 +173,12 @@ ...@@ -187,12 +173,12 @@
[self hideLoading]; [self hideLoading];
if ([[self.viewModel fetchDataSuccess] boolValue]) { if ([[self.viewModel fetchDataSuccess] boolValue]) {
if ([[self.viewModel dataArray] count] == 0) { if ([[self.viewModel dataArray] count] == 0) {
[self showEmptyView:OCEmptyViewTypeEmpty]; [self showEmptyView:GMEmptyViewTypeEmpty];
}else { }else {
[self hideEmptyView]; [self hideEmptyView];
} }
}else{ }else{
[self showEmptyView:OCEmptyViewTypeException]; [self showEmptyView:GMEmptyViewTypeException];
} }
if (_table!=nil) { if (_table!=nil) {
...@@ -206,19 +192,6 @@ ...@@ -206,19 +192,6 @@
} }
} }
- (void)showEmptyView:(OCEmptyViewType)type {
_emptyView.type = type;
_emptyView.hidden = NO;
_emptyView.tipText = [self getEmptyText];
[_emptyView setNeedsUpdateConstraints];
}
- (void)hideEmptyView {
_emptyView.hidden = YES;
}
- (void)dealloc{ - (void)dealloc{
[self removeKVO]; [self removeKVO];
// 因为fetchDataSuccess是在viewDidLoad中监听的,所以需要一个判断 // 因为fetchDataSuccess是在viewDidLoad中监听的,所以需要一个判断
...@@ -227,9 +200,8 @@ ...@@ -227,9 +200,8 @@
} }
} }
#pragma mark - OCEmptyViewDelegate #pragma mark - GMEmptyView
- (void)emptyViewDidClickReload {
- (void)emptyViewDidClickReload{
[self loadRemoteData]; [self loadRemoteData];
} }
...@@ -239,6 +211,4 @@ ...@@ -239,6 +211,4 @@
} }
return @""; return @"";
} }
@end @end
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "OCNavigatioinBar.h" #import "OCNavigatioinBar.h"
#import "UIViewController+HUD.h"
#import <GMPhobos/GMPhobos-umbrella.h> #import <GMPhobos/GMPhobos-umbrella.h>
@import GMKit;
@interface WMBaseViewController : UIViewController <OCNavigatioinBarDelegate> @interface WMBaseViewController : UIViewController <OCNavigatioinBarDelegate, GMEmptyViewDelegate>
@property (nonatomic, strong) OCNavigatioinBar *navigationBar; @property (nonatomic, strong) OCNavigatioinBar *navigationBar;
/** /**
默认值为NO,表示导航栏自动被WMBaseViewController管理,永远在所有的view最上方。 默认值为NO,表示导航栏自动被WMBaseViewController管理,永远在所有的view最上方。
...@@ -19,9 +19,27 @@ ...@@ -19,9 +19,27 @@
*/ */
@property (nonatomic, assign) BOOL controlNavigationByYou; @property (nonatomic, assign) BOOL controlNavigationByYou;
@property (nonatomic, strong) GMEmptyView *emptyView;
/** /**
* @brief 因为controller会有initWithCoder,init,initWithNib三种方式,为了避免子类代码的疏忽导致父类自定义init内容没有覆盖到,所以统一使用initController方法。需要调用super * @brief 因为controller会有initWithCoder,init,initWithNib三种方式,为了避免子类代码的疏忽导致父类自定义init内容没有覆盖到,所以统一使用initController方法。需要调用super
*/ */
- (void)initController __attribute__((objc_requires_super)); - (void)initController __attribute__((objc_requires_super));
- (void)pushViewController:(UIViewController *)controller; - (void)pushViewController:(UIViewController *)controller;
#pragma mark - Empty
- (void)showEmptyView:(GMEmptyViewType)type;
- (void)hideEmptyView;
/*!
* @author zhaiguojun, 16-06-28
*
* @brief 给子类设置空view的文案
*
* @param text
*
* @since 6.1.0
*/
- (NSString *)getEmptyText;
- (void)emptyViewDidClickReload;
@end @end
...@@ -61,6 +61,20 @@ ...@@ -61,6 +61,20 @@
[self hideLeftButtonForRootController]; [self hideLeftButtonForRootController];
//保证一些网络请求需要接参数referer的时候referer是有值的 //保证一些网络请求需要接参数referer的时候referer是有值的
[self initReferer]; [self initReferer];
[self setupEmptyView];
}
- (void)setupEmptyView {
_emptyView = [[GMEmptyView alloc] initWithFrame:CGRectZero];
_emptyView.hidden = YES;
_emptyView.delegate = self;
[self.view addSubview:_emptyView];
[_emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.top.mas_equalTo(0);
make.bottom.mas_equalTo(0);
}];
} }
- (void)viewDidLayoutSubviews { - (void)viewDidLayoutSubviews {
...@@ -156,4 +170,18 @@ ...@@ -156,4 +170,18 @@
[self dismissViewControllerAnimated:YES completion:nil]; [self dismissViewControllerAnimated:YES completion:nil];
} }
} }
#pragma mark - GMEmptyView
- (void)showEmptyView:(GMEmptyViewType)type {
_emptyView.type = type;
_emptyView.hidden = NO;
[self.view bringSubviewToFront:_emptyView];
}
- (void)hideEmptyView {
_emptyView.hidden = YES;
}
- (void)emptyViewDidClickReload {}
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment