Skip to content

Commit 0eee2f4

Browse files
committed
[Feature]实现会员登录成功后首页增加会员专属菜类
[Bugfix]修正首页菜品展示框宽度不对的问题
1 parent 8fee74b commit 0eee2f4

File tree

7 files changed

+94
-59
lines changed

7 files changed

+94
-59
lines changed

DianXiaoEr-Menu-iOS/ViewControllers/DXEHomePageViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
#import <UIKit/UIKit.h>
1010

1111
@interface DXEHomePageViewController : UIViewController
12+
13+
- (void)showAllDishClasses;
14+
1215
@end

DianXiaoEr-Menu-iOS/ViewControllers/DXEHomePageViewController.m

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

DianXiaoEr-Menu-iOS/ViewControllers/DXEMainViewController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ - (void)onLoginButtonClickedInLoginView:(DXELoginView *)loginView
223223
{
224224
[self.tabBar setItemSelectedAtIndex:DXEMainChildViewControllerIndexMyself];
225225
[self moveToChildViewControllerAtIndex:DXEMainChildViewControllerIndexMyself];
226+
DXEHomePageViewController *homepage = [self.contentViewControllers objectAtIndex:DXEMainChildViewControllerIndexHomepage];
227+
[homepage showAllDishClasses];
226228
}
227229
[CRModal dismiss];
228230
}

DianXiaoEr-Menu-iOS/Views/DXEDishCollectionViewCell.xib

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
99
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
1010
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="lGy-eV-7UU" customClass="DXEDishCollectionViewCell">
11-
<rect key="frame" x="0.0" y="0.0" width="357" height="597"/>
11+
<rect key="frame" x="0.0" y="0.0" width="359" height="597"/>
1212
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
1313
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
14-
<rect key="frame" x="0.0" y="0.0" width="357" height="597"/>
14+
<rect key="frame" x="0.0" y="0.0" width="359" height="597"/>
1515
<autoresizingMask key="autoresizingMask"/>
1616
<subviews>
1717
<imageView contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="WYt-MK-oMy">
18-
<rect key="frame" x="0.0" y="0.0" width="357" height="490"/>
18+
<rect key="frame" x="0.0" y="0.0" width="359" height="493"/>
1919
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2020
</imageView>
2121
<imageView hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="5lv-Qv-GM5">
22-
<rect key="frame" x="0.0" y="0.0" width="357" height="490"/>
22+
<rect key="frame" x="0.0" y="0.0" width="359" height="493"/>
2323
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2424
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
2525
</imageView>
@@ -94,20 +94,20 @@
9494
<action selector="onCartButtonClicked:" destination="lGy-eV-7UU" eventType="touchUpInside" id="fmN-R8-i1I"/>
9595
</connections>
9696
</button>
97+
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="dish_cell_incart_flag.png" id="Wlk-pd-TLg">
98+
<rect key="frame" x="297" y="0.0" width="39" height="55"/>
99+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
100+
</imageView>
97101
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="dish_cell_cart_icon.png" id="GUm-mw-jfo">
98102
<rect key="frame" x="269" y="559" width="20" height="16"/>
99103
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
100104
</imageView>
101-
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="dish_cell_incart_flag.png" id="Wlk-pd-TLg">
102-
<rect key="frame" x="297" y="0.0" width="40" height="55"/>
103-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
104-
</imageView>
105105
</subviews>
106106
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
107107
</view>
108108
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
109109
<gestureRecognizers/>
110-
<size key="customSize" width="360" height="602"/>
110+
<size key="customSize" width="363" height="602"/>
111111
<connections>
112112
<outlet property="cartButton" destination="nkE-DL-tOJ" id="jgH-oH-7jD"/>
113113
<outlet property="cartIcon" destination="GUm-mw-jfo" id="HHN-7N-7Wh"/>
@@ -122,6 +122,7 @@
122122
<outlet property="maskView" destination="5lv-Qv-GM5" id="Jke-EK-BV4"/>
123123
<outlet property="soldoutFlag" destination="Q8a-d1-nxm" id="KdM-2z-VrN"/>
124124
</connections>
125+
<point key="canvasLocation" x="141" y="153.5"/>
125126
</collectionViewCell>
126127
</objects>
127128
<resources>

DianXiaoEr-Menu-iOS/Views/DXEOrderCartTableViewCell.xib

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="6245" systemVersion="13E28" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
55
</dependencies>
66
<objects>
77
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -14,7 +14,7 @@
1414
<autoresizingMask key="autoresizingMask"/>
1515
<subviews>
1616
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="vF3-Ok-TXu" userLabel="BackgroundImageView">
17-
<rect key="frame" x="0.0" y="3" width="702" height="134"/>
17+
<rect key="frame" x="0.0" y="3" width="702" height="135"/>
1818
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1919
</imageView>
2020
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="Oj3-0Q-8UU" userLabel="DishThumbnail">
@@ -133,4 +133,9 @@
133133
<image name="order_cell_increase_disable_button.png" width="19" height="19"/>
134134
<image name="order_cell_increase_normal_button.png" width="19" height="19"/>
135135
</resources>
136+
<simulatedMetricsContainer key="defaultSimulatedMetrics">
137+
<simulatedStatusBarMetrics key="statusBar"/>
138+
<simulatedOrientationMetrics key="orientation"/>
139+
<simulatedScreenMetrics key="destination"/>
140+
</simulatedMetricsContainer>
136141
</document>

0 commit comments

Comments
 (0)