@@ -32,6 +32,7 @@ @interface DXEHomePageViewController ()
3232
3333@property (nonatomic , strong ) CRScrollMenuController *scrollMenuController;
3434@property (nonatomic , strong ) NSMutableArray *contentViewControllers;
35+ @property (nonatomic , strong ) NSMutableArray *scrollMenuItems;
3536@property (nonatomic , strong ) NSMutableArray *showDishes;
3637@property (nonatomic , strong ) NSMutableArray *hideDishes;
3738
@@ -47,9 +48,11 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
4748 if (self)
4849 {
4950 NSPredicate *showPredicate = [NSPredicate predicateWithFormat: @" name != %@" , @" 会员" ];
50- _showDishes = [NSMutableArray arrayWithArray: [[DXEDishDataManager sharedInstance ].dishClasses filteredArrayUsingPredicate: showPredicate]];
51+ _showDishes = [NSMutableArray arrayWithArray: [[DXEDishDataManager sharedInstance ].dishClasses
52+ filteredArrayUsingPredicate: showPredicate]];
5153 NSPredicate *hidePredicate = [NSPredicate predicateWithFormat: @" name = %@" , @" 会员" ];
52- _hideDishes = [NSMutableArray arrayWithArray: [[DXEDishDataManager sharedInstance ].dishClasses filteredArrayUsingPredicate: hidePredicate]];
54+ _hideDishes = [NSMutableArray arrayWithArray: [[DXEDishDataManager sharedInstance ].dishClasses
55+ filteredArrayUsingPredicate: hidePredicate]];
5356
5457 [[DXEOrderManager sharedInstance ] addObserver: self
5558 forKeyPath: NSStringFromSelector (@selector (cartList ))
@@ -106,30 +109,13 @@ - (void)viewDidLoad
106109 [self .view addSubview: self .scrollMenuController.view];
107110 [self .scrollMenuController didMoveToParentViewController: self ];
108111
109- NSMutableArray *items = [NSMutableArray arrayWithCapacity: [self .showDishes count ]];
110112 self.contentViewControllers = [NSMutableArray arrayWithCapacity: [self .showDishes count ]];
111- for (DXEDishClass *class in self.showDishes )
112- {
113- CHTCollectionViewWaterfallLayout *layout = [[CHTCollectionViewWaterfallLayout alloc ] init ];
114- layout.sectionInset = UIEdgeInsetsMake (kDXECollectionViewSectionTop ,
115- kDXECollectionViewSectionLeft ,
116- kDXECollectionViewSectionBottom ,
117- kDXECollectionViewSectionRight );
118- layout.headerHeight = kDXECollectionViewHeaderHeight ;
119- layout.footerHeight = kDXECollectionViewFooterHeight ;
120- layout.minimumColumnSpacing = kDXECollectionViewColumnSpacing ;
121- layout.minimumInteritemSpacing = kDXECollectionViewInteritemSpacing ;
122-
123- DXEDishesViewController *dishViewController = [[DXEDishesViewController alloc ] initWithCollectionViewLayout: layout];
124- dishViewController.dishClass = class;
125- [self .contentViewControllers addObject: dishViewController];
126-
127- CRScrollMenuItem *item = [[CRScrollMenuItem alloc ] init ];
128- item.title = class.name ;
129- item.subtitle = class.englishName ;
130- [items addObject: item];
131- }
132- [self .scrollMenuController setViewControllers: self .contentViewControllers withItems: items];
113+ self.scrollMenuItems = [NSMutableArray arrayWithCapacity: [self .showDishes count ]];
114+ [self .showDishes enumerateObjectsUsingBlock: ^(DXEDishClass *class, NSUInteger index, BOOL *stop){
115+ [self generateContentControllerByData: class atIndex: index];
116+ }];
117+ [self .scrollMenuController setViewControllers: self .contentViewControllers
118+ withItems: self .scrollMenuItems];
133119}
134120
135121- (void )viewWillAppear : (BOOL )animated
@@ -139,6 +125,49 @@ - (void)viewWillAppear:(BOOL)animated
139125 self.scrollMenuController .view .frame = self.view .bounds ;
140126}
141127
128+ - (void )generateContentControllerByData : (DXEDishClass *)class
129+ atIndex : (NSInteger )index
130+ {
131+ CHTCollectionViewWaterfallLayout *layout = [[CHTCollectionViewWaterfallLayout alloc ] init ];
132+ layout.sectionInset = UIEdgeInsetsMake (kDXECollectionViewSectionTop ,
133+ kDXECollectionViewSectionLeft ,
134+ kDXECollectionViewSectionBottom ,
135+ kDXECollectionViewSectionRight );
136+ layout.headerHeight = kDXECollectionViewHeaderHeight ;
137+ layout.footerHeight = kDXECollectionViewFooterHeight ;
138+ layout.minimumColumnSpacing = kDXECollectionViewColumnSpacing ;
139+ layout.minimumInteritemSpacing = kDXECollectionViewInteritemSpacing ;
140+
141+ DXEDishesViewController *dishViewController = [[DXEDishesViewController alloc ] initWithCollectionViewLayout: layout];
142+ dishViewController.dishClass = class;
143+ [self .contentViewControllers insertObject: dishViewController atIndex: index];
144+
145+ CRScrollMenuItem *item = [[CRScrollMenuItem alloc ] init ];
146+ item.title = class.name ;
147+ item.subtitle = class.englishName ;
148+ [self .scrollMenuItems insertObject: item atIndex: index];
149+ }
150+
151+ - (void )showAllDishClasses
152+ {
153+ for (DXEDishClass *hideClass in self.hideDishes )
154+ {
155+ __block NSUInteger insertIndex = 0 ;
156+ [self .showDishes enumerateObjectsUsingBlock: ^(DXEDishClass *showClass, NSUInteger index, BOOL *stop){
157+ if ([hideClass.showSequence integerValue ] < [showClass.showSequence integerValue ])
158+ {
159+ [self .showDishes insertObject: hideClass atIndex: index];
160+ insertIndex = index;
161+ *stop = YES ;
162+ }
163+ }];
164+ [self generateContentControllerByData: hideClass atIndex: insertIndex];
165+ }
166+ [self .scrollMenuController setViewControllers: self .contentViewControllers
167+ withItems: self .scrollMenuItems];
168+ [self .hideDishes removeAllObjects ];
169+ }
170+
142171#pragma mark - notification
143172
144173- (void )observeValueForKeyPath : (NSString *)keyPath
0 commit comments