Commit 5835f419 by lee

Merge branch 'master' of git.oschina.net:kollway-kollway/newcemarose

parents e5cac07b 5bcdb8f1
......@@ -22,5 +22,7 @@
@property (nonatomic) NSMutableArray<KWMFilter *> *filters;
@property (nonatomic) NSString *brand;
@property (nonatomic) CGFloat offsetY;
//切换分类后,如果原来有选中筛选规则的需要清除并重新刷新,以此字段标识
@property (nonatomic) BOOL isNeedReload;
@end
......@@ -67,6 +67,7 @@
[self initData];
[self initView];
[self requestAllBrandsApi];
[self registerResetPageNotification];
// [self.refreshUtil reLoadData];
// [self.cvRightProduct.mj_header beginRefreshing];
}
......@@ -85,6 +86,14 @@
[self.navigationController setNavigationBarHidden:NO];
}
-(void)dealloc{
//如果大于等于ios9.0,不需要反注册了,从ios9.0开始通知中心会对观察者弱引用
NSString *version = [UIDevice currentDevice].systemVersion;
if (version.doubleValue < 9.0) {
[self unRegisterNotification];
}
}
-(KWMCollectionRefreshUtil *)refreshUtil{
if(!_refreshUtil){
_refreshUtil = [KWMCollectionRefreshUtil new];
......@@ -161,6 +170,66 @@
[self initCustomTitleBarConstarints:self.titleView];
}
#pragma mark -- resetFilter resetPager
/* 每次切换tab和从首页重新回来的时候,都会清空筛选和选回首个分类
每次切换分类,都会清空掉该分类的筛选 */
//注册and反注册 重置筛选和选中分类的广播
-(void)registerResetPageNotification{
//从后台返回前台时
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetPager)name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetPager)name:@"didSelectCategoryTab" object:nil];
}
-(void)unRegisterNotification{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)resetPager{
[self resetAllOffset];
[self resetAllFilter];
[self resetCategorySelected];
}
//移除筛选
//需要被重置的分类,标示isNeedReload,下次进入时,刷新
-(void)resetAllFilter{
for (KWMCategoryModel *category in self.categories) {
BOOL isNeedReload = NO;
if(category.filters && category.filters.count > 0){
[category.filters removeAllObjects];
isNeedReload = YES;
}
if(category.sort != BUYCollectionSortCollectionDefault){
category.sort = BUYCollectionSortCollectionDefault;
isNeedReload = YES;
}
if(category.brand){
category.brand = nil;
isNeedReload = YES;
}
if(isNeedReload){
category.isNeedReload = YES;
category.offsetY = 0;
}
}
}
-(void)resetAllOffset{
self.cvRightProduct.contentOffset = CGPointMake(0, 0);
for (KWMCategoryModel *category in self.categories) {
category.offsetY = 0;
}
}
-(void)resetCategorySelected{
self.selectedCategory = self.categories.firstObject;
NSIndexPath * path = [NSIndexPath indexPathForItem:0 inSection:0];
if([self.tbvLeftCategory numberOfRowsInSection:0]>0){
[self.tbvLeftCategory selectRowAtIndexPath:path animated:YES scrollPosition:UITableViewScrollPositionTop];
}
}
#pragma mark -- KWMCategoryTitleDelegate
-(void)kwm_onClickShopCart{
KWMShopCartVC * shopCartVC = (KWMShopCartVC*)[KWMBaseVC findControllerBy:[KWMShopCartVC kwmTag] fromStoryboard:@"ShopCart"];
......@@ -191,6 +260,7 @@
// [self.cvRightProduct.mj_header endRefreshing];
// [self.cvRightProduct.mj_footer endRefreshing];
self.selectedCategory = self.categories[indexPath.row];
[self resetAllFilter];
}
#pragma mark - UICollectionViewDataSource
......@@ -316,6 +386,7 @@
self.filterTab.userInteractionEnabled = false;
KWMCategoryModel *cmodel = self.selectedCategory;
cmodel.isNeedReload = NO;
NSMutableArray *tags = [KWMFilterUtil getTagsByFilterArray:cmodel.filters];
if(cmodel.brand){
[tags addObject:cmodel.brand];
......@@ -384,6 +455,8 @@
}else{
[self.cvRightProduct.mj_header beginRefreshing];
}
}else if(_selectedCategory.isNeedReload){
[self.refreshUtil reLoadData];
}else if([self.cvRightProduct.mj_header isRefreshing]) {
[self.cvRightProduct.mj_header endRefreshing];
}
......
......@@ -181,6 +181,7 @@
tabBarItem2.image = image2;
image2 = [[UIImage imageNamed:@"btn_tab_store_pre"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem2.selectedImage = image2;
tabBarItem2.tag = 101;
UIImage *image3 = [[UIImage imageNamed:@"btn_tab_ brand"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
......@@ -216,6 +217,12 @@
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
// 这里不需要调用super,因为父类没有实现这个代理方法
//[super tabBar:tabBar didSelectItem:item];
if(item.tag == 101){
[[NSNotificationCenter defaultCenter] postNotificationName:@"didSelectCategoryTab" object:nil];
}
}
@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