Commit f961aa2c by houweibin

1,切换分类后,会重置前一个分类的筛选

2,切换tab以及返回前台后,将重新选中首个分类,并重置所有分类的筛选
parent 18b81387
...@@ -22,5 +22,7 @@ ...@@ -22,5 +22,7 @@
@property (nonatomic) NSMutableArray<KWMFilter *> *filters; @property (nonatomic) NSMutableArray<KWMFilter *> *filters;
@property (nonatomic) NSString *brand; @property (nonatomic) NSString *brand;
@property (nonatomic) CGFloat offsetY; @property (nonatomic) CGFloat offsetY;
//切换分类后,如果原来有选中筛选规则的需要清除并重新刷新,以此字段标识
@property (nonatomic) BOOL isNeedReload;
@end @end
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self registerResetPageNotification];
[self initData]; [self initData];
[self initView]; [self initView];
[self requestAllBrandsApi]; [self requestAllBrandsApi];
...@@ -85,6 +86,14 @@ ...@@ -85,6 +86,14 @@
[self.navigationController setNavigationBarHidden:NO]; [self.navigationController setNavigationBarHidden:NO];
} }
-(void)dealloc{
//如果大于等于ios9.0,不需要反注册了,从ios9.0开始通知中心会对观察者弱引用
NSString *version = [UIDevice currentDevice].systemVersion;
if (version.doubleValue < 9.0) {
[self unRegisterNotification];
}
}
-(KWMCollectionRefreshUtil *)refreshUtil{ -(KWMCollectionRefreshUtil *)refreshUtil{
if(!_refreshUtil){ if(!_refreshUtil){
_refreshUtil = [KWMCollectionRefreshUtil new]; _refreshUtil = [KWMCollectionRefreshUtil new];
...@@ -161,6 +170,66 @@ ...@@ -161,6 +170,66 @@
[self initCustomTitleBarConstarints:self.titleView]; [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 #pragma mark -- KWMCategoryTitleDelegate
-(void)kwm_onClickShopCart{ -(void)kwm_onClickShopCart{
KWMShopCartVC * shopCartVC = (KWMShopCartVC*)[KWMBaseVC findControllerBy:[KWMShopCartVC kwmTag] fromStoryboard:@"ShopCart"]; KWMShopCartVC * shopCartVC = (KWMShopCartVC*)[KWMBaseVC findControllerBy:[KWMShopCartVC kwmTag] fromStoryboard:@"ShopCart"];
...@@ -191,6 +260,7 @@ ...@@ -191,6 +260,7 @@
// [self.cvRightProduct.mj_header endRefreshing]; // [self.cvRightProduct.mj_header endRefreshing];
// [self.cvRightProduct.mj_footer endRefreshing]; // [self.cvRightProduct.mj_footer endRefreshing];
self.selectedCategory = self.categories[indexPath.row]; self.selectedCategory = self.categories[indexPath.row];
[self resetAllFilter];
} }
#pragma mark - UICollectionViewDataSource #pragma mark - UICollectionViewDataSource
...@@ -316,6 +386,7 @@ ...@@ -316,6 +386,7 @@
self.filterTab.userInteractionEnabled = false; self.filterTab.userInteractionEnabled = false;
KWMCategoryModel *cmodel = self.selectedCategory; KWMCategoryModel *cmodel = self.selectedCategory;
cmodel.isNeedReload = NO;
NSMutableArray *tags = [KWMFilterUtil getTagsByFilterArray:cmodel.filters]; NSMutableArray *tags = [KWMFilterUtil getTagsByFilterArray:cmodel.filters];
if(cmodel.brand){ if(cmodel.brand){
[tags addObject:cmodel.brand]; [tags addObject:cmodel.brand];
...@@ -384,6 +455,8 @@ ...@@ -384,6 +455,8 @@
}else{ }else{
[self.cvRightProduct.mj_header beginRefreshing]; [self.cvRightProduct.mj_header beginRefreshing];
} }
}else if(_selectedCategory.isNeedReload){
[self.refreshUtil reLoadData];
}else if([self.cvRightProduct.mj_header isRefreshing]) { }else if([self.cvRightProduct.mj_header isRefreshing]) {
[self.cvRightProduct.mj_header endRefreshing]; [self.cvRightProduct.mj_header endRefreshing];
} }
......
...@@ -181,6 +181,7 @@ ...@@ -181,6 +181,7 @@
tabBarItem2.image = image2; tabBarItem2.image = image2;
image2 = [[UIImage imageNamed:@"btn_tab_store_pre"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; image2 = [[UIImage imageNamed:@"btn_tab_store_pre"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem2.selectedImage = image2; tabBarItem2.selectedImage = image2;
tabBarItem2.tag = 101;
UIImage *image3 = [[UIImage imageNamed:@"btn_tab_ brand"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UIImage *image3 = [[UIImage imageNamed:@"btn_tab_ brand"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
...@@ -216,6 +217,12 @@ ...@@ -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 @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