FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Controllers/Shop/ShopViewController.m at master · kasumar/Coding-iOS · GitHub
kasumar
/
Coding-iOS
Public
forked from
coding/Coding-iOS
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
Shop
/
ShopViewController.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
369 lines (293 loc) · 11 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
Shop
/
ShopViewController.m
Copy path
File metadata and controls
369 lines (293 loc) · 11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
//
//
ShopViewController.m
//
Coding_iOS
//
//
Created by liaoyp on 15/11/20.
//
Copyright © 2015年 Coding. All rights reserved.
//
#
import
"
ShopViewController.h
"
#
import
"
ShopOrderViewController.h
"
#
import
"
ExchangeGoodsViewController.h
"
#
import
"
WebViewController.h
"
#
import
"
XTSegmentControl.h
"
#
import
"
ShopBannerView.h
"
#
import
"
ShopGoodsCCell.h
"
#
import
"
ODRefreshControl.h
"
#
import
"
Shop.h
"
#
import
"
ShopBanner.h
"
#
import
"
iCarousel.h
"
@class
ShopListView;
#
import
"
Coding_NetAPIManager.h
"
#
import
"
UIScrollView+SVInfiniteScrolling.h
"
@protocol
ShopListViewDelegate
<
NSObject
>
- (
void
)
startRefreWithShopView
:
(ShopListView *)
listView
;
- (
void
)
didSelectGoodItem
:
(ShopGoods *)
good
;
@end
@interface
ShopListView
:
UIView
@property
(
nonatomic
,
weak
)
id
<ShopListViewDelegate> delegate;
@property
(
nonatomic
,
strong
)
NSArray
*dataSource;
@property
(
nonatomic
,
strong
,
readonly
)ODRefreshControl *myRefreshControl;
@end
@interface
ShopViewController
()<iCarouselDataSource,iCarouselDelegate,ShopListViewDelegate>
{
UIView *_collectionHeaderView;
XTSegmentControl *_shopSegmentControl;
ShopBannerView *_shopBannerView;
NSInteger
_oldSelectedIndex;
BOOL
_isRequest;
}
@property
(
strong
,
nonatomic
) XTSegmentControl *mySegmentControl;
@property
(
strong
,
nonatomic
)
NSArray
*titlesArray;
@property
(
strong
,
nonatomic
) iCarousel *myCarousel;
@property
(
nonatomic
,
strong
)Shop *shopObject;
@end
@implementation
ShopViewController
#
pragma
mark-
#
pragma
mark---------------------- Button事件 ---------------------------
- (
void
)
exchangeHistoryBtnClicked
:
(UIButton *)
button
{
ShopOrderViewController *orderViewController = [[ShopOrderViewController
alloc
]
init
];
[
self
.navigationController
pushViewController:
orderViewController
animated:
YES
];
}
- (
void
)
startRefreWithShopView
:
(ShopListView *)
listView
{
__weak
typeof
(self) weakSelf = self;
__weak
typeof
(iCarousel) *weakCarousel = _myCarousel;
[[Coding_NetAPIManager
sharedManager
]
request_shop_giftsWithShop:
_shopObject
andBlock:
^(
id
data,
NSError
*error) {
[weakSelf.view
endLoading
];
[listView.myRefreshControl
endRefreshing
];
if
(data) {
[weakSelf
carouselCurrentItemIndexDidChange:
weakCarousel];
}
else
[
NSObject
showHudTipStr:
@"
Error
"
];
}];
}
- (
void
)
bannerClicked
:
(
NSString
*)
linkStr
{
if
(linkStr.
length
<=
0
) {
return
;
}
UIViewController *vc = [BaseViewController
analyseVCFromLinkStr:
linkStr];
if
(vc) {
[
self
.navigationController
pushViewController:
vc
animated:
YES
];
}
else
{
//
网页
WebViewController *webVc = [WebViewController
webVCWithUrlStr:
linkStr];
[
self
.navigationController
pushViewController:
webVc
animated:
YES
];
}
}
#
pragma
mark---------------------- ShopListViewDelegate --------------------
- (
void
)
didSelectGoodItem
:
(ShopGoods *)
model
{
if
(!model.
exchangeable
) {
[
NSObject
showHudTipStr:
@"
您的码币余额不足,不能兑换该商品
"
];
return
;
}
ExchangeGoodsViewController *exChangeViewController = [[ExchangeGoodsViewController
alloc
]
init
];
exChangeViewController.
shopGoods
= model;
[
self
.navigationController
pushViewController:
exChangeViewController
animated:
YES
];
}
#
pragma
mark-
#
pragma
mark---------------------- ControllerLife ---------------------------
- (
void
)
viewDidLoad
{
[
super
viewDidLoad
];
//
Do any additional setup after loading the view, typically from a nib.
self.
title
=
@"
我的商城
"
;
_shopObject = [[Shop
alloc
]
init
];
_shopObject.
shopType
= ShopTypeAll;
[
self
setUpView
];
//
一次性加载所有数据,暂时没有做分页的需要,先注释.
//
__weak typeof(self) weakSelf = self;
//
[_collectionView addInfiniteScrollingWithActionHandler:^{
//
[weakSelf refreshMore];
//
}];
[
self
.navigationItem
setRightBarButtonItem:
[[UIBarButtonItem
alloc
]
initWithImage:
[UIImage
imageNamed:
@"
shop_nar_history_icon
"
]
style:
UIBarButtonItemStylePlain
target:
self
action:
@selector
(
exchangeHistoryBtnClicked:
)]
animated:
NO
];
}
- (
void
)
viewDidAppear
:
(
BOOL
)
animated
{
[
super
viewDidAppear:
animated];
if
(!_isRequest) {
_isRequest =
YES
;
[
self
requestgiftsList
];
}
}
#
pragma
mark-
#
pragma
mark---------------------- 网络请求 ---------------------------
- (
void
)
refreshMore
{
if
(!_shopObject.
isLoading
|| !_shopObject.
canLoadMore
) {
return
;
}
_shopObject.
willLoadMore
=
YES
;
_shopObject.
page
= @(_shopObject.
page
.
intValue
+
1
);
[
self
loadGiftsList
];
}
- (
void
)
requestgiftsList
{
[
self
.view
beginLoading
];
__weak
typeof
(self) weakSelf = self;
//
[[Coding_NetAPIManager sharedManager] request_shop_bannersWithBlock:^(id data, NSError *error) {
//
weakSelf.shopObject.shopBannerArray = data;
//
}];
[[Coding_NetAPIManager
sharedManager
]
request_shop_userPointWithShop:
_shopObject
andBlock:
^(
id
data,
NSError
*error) {
if
(data) {
[weakSelf
loadGiftsList
];
}
}];
}
- (
void
)
loadGiftsList
{
__weak
typeof
(self) weakSelf = self;
[[Coding_NetAPIManager
sharedManager
]
request_shop_giftsWithShop:
_shopObject
andBlock:
^(
id
data,
NSError
*error) {
[weakSelf.view
endLoading
];
if
(data) {
ShopListView *listView = (ShopListView *)[weakSelf.myCarousel
currentItemView
];
listView.
dataSource
= weakSelf.
shopObject
.
dateSource
;
}
else
[
NSObject
showHudTipStr:
@"
Error
"
];
}];
}
- (
void
)
setUpView
{
//
添加myCarousel
self.
myCarousel
= ({
iCarousel *icarousel = [[iCarousel
alloc
]
initWithFrame:
CGRectZero];
icarousel.
dataSource
= self;
icarousel.
delegate
= self;
icarousel.
decelerationRate
=
1.0
;
icarousel.
scrollSpeed
=
1.0
;
icarousel.
type
= iCarouselTypeLinear;
icarousel.
pagingEnabled
=
YES
;
icarousel.
clipsToBounds
=
YES
;
icarousel.
bounceDistance
=
0.2
;
[
self
.view
addSubview:
icarousel];
[icarousel
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
edges
.
equalTo
(self.
view
).
insets
(
UIEdgeInsetsMake
(
kMySegmentControl_Height
,
0
,
0
,
0
));
}];
icarousel;
});
__weak
typeof
(self) weakSelf = self;
self.
mySegmentControl
= [[XTSegmentControl
alloc
]
initWithFrame:
CGRectMake
(
0
,
0
,
kScreen_Width
,
kMySegmentControl_Height
)
Items:
self
.titlesArray
selectedBlock:
^(
NSInteger
index) {
[weakSelf.myCarousel
scrollToItemAtIndex:
index
animated:
NO
];
}];
[
self
.view
addSubview:
self
.mySegmentControl];
}
#
pragma mark
- Getter/Setter
- (
NSArray
*)
titlesArray
{
if
(
nil
== _titlesArray) {
_titlesArray = @[
@"
全部商品
"
,
@"
可兑换商品
"
];
}
return
_titlesArray;
}
#
pragma mark
iCarousel M
- (
NSUInteger
)
numberOfItemsInCarousel
:
(iCarousel *)
carousel
{
return
[
self
.titlesArray
count
];
}
- (UIView *)
carousel
:
(iCarousel *)
carousel
viewForItemAtIndex
:
(
NSUInteger
)
index
reusingView
:
(UIView *)
view
{
ShopListView *listView = (ShopListView *)view;
if
(listView) {
}
else
{
listView = [[ShopListView
alloc
]
initWithFrame:
carousel.bounds];
}
listView.
delegate
= self;
[listView
setSubScrollsToTop:
(index == carousel.currentItemIndex)];
return
listView;
}
- (
void
)
carouselDidScroll
:
(iCarousel *)
carousel
{
if
(_mySegmentControl) {
float
offset = carousel.
scrollOffset
;
if
(offset >
0
) {
[_mySegmentControl
moveIndexWithProgress:
offset];
}
}
}
- (
void
)
carouselCurrentItemIndexDidChange
:
(iCarousel *)
carousel
{
ShopListView *listView = (ShopListView *)carousel.
currentItemView
;
if
(_mySegmentControl) {
_mySegmentControl.
currentIndex
= carousel.
currentItemIndex
;
}
if
(carousel.
currentItemIndex
==
0
) {
listView.
dataSource
= _shopObject.
dateSource
;
}
else
if
(carousel.
currentItemIndex
==
1
)
{
listView.
dataSource
= [_shopObject
getExchangeGiftData
];
}
[carousel.visibleItemViews
enumerateObjectsUsingBlock:
^(UIView *obj,
NSUInteger
idx,
BOOL
*stop) {
[obj
setSubScrollsToTop:
(obj == carousel.currentItemView)];
}];
}
- (
void
)
didReceiveMemoryWarning
{
[
super
didReceiveMemoryWarning
];
//
Dispose of any resources that can be recreated.
}
- (
void
)
dealloc
{
_myCarousel.
delegate
=
nil
;
_myCarousel.
dataSource
=
nil
;
}
@end
@interface
ShopListView
() <UICollectionViewDataSource,UICollectionViewDelegate>
{
UICollectionView *_collectionView;
}
@end
@implementation
ShopListView
- (
instancetype
)
initWithFrame
:
(CGRect)
frame
{
self = [
super
initWithFrame:
frame];
if
(self) {
[
self
setUpCollectionView
];
}
return
self;
}
- (
void
)
setUpCollectionView
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout
alloc
]
init
];
CGFloat itemW = (
kScreen_Width
-
12
*
3
) /
2
;
CGFloat itemH = itemW * (
175.0
/
284.0
) +
10
+
21
+
5
+
13
+
5
;
layout.
itemSize
=
CGSizeMake
(itemW, itemH);
layout.
sectionInset
=
UIEdgeInsetsMake
(
20
,
12
,
20
,
12
);
layout.
minimumInteritemSpacing
=
5
;
layout.
minimumLineSpacing
=
20
;
_collectionView = [[UICollectionView
alloc
]
initWithFrame:
self
.bounds
collectionViewLayout:
layout];
_collectionView.
backgroundColor
= [UIColor
clearColor
];
[_collectionView
registerClass:
[ShopGoodsCCell
class
]
forCellWithReuseIdentifier:
@"
TopicProductCollectionCellIdentifier
"
];
_collectionView.
dataSource
= self;
_collectionView.
delegate
= self;
_collectionView.
layer
.
masksToBounds
=
NO
;
[
self
addSubview:
_collectionView];
_myRefreshControl = [[ODRefreshControl
alloc
]
initInScrollView:
_collectionView];
[_myRefreshControl
addTarget:
self
action:
@selector
(
refresh
)
forControlEvents:
UIControlEventValueChanged];
}
- (
void
)
refresh
{
if
(_delegate && [_delegate
respondsToSelector:
@selector
(
startRefreWithShopView:
)]) {
[_delegate
startRefreWithShopView:
self
];
}
}
- (
void
)
setDataSource
:
(
NSArray
*)
dataSource
{
_dataSource = dataSource;
[_collectionView
reloadData
];
[
self
configBlankPage:
EaseBlankPageTypeNoExchangeGoods
hasData:
_dataSource.count >
0
hasError:
NO
reloadButtonBlock:
^(
id
sender) {
}];
}
#
pragma mark
- UICollectionViewDataSource
- (
NSInteger
)
collectionView
:
(UICollectionView *)
collectionView
numberOfItemsInSection
:
(
NSInteger
)
section
{
return
_dataSource.
count
;
}
- (UICollectionViewCell *)
collectionView
:
(UICollectionView *)
collectionView
cellForItemAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
ShopGoodsCCell *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:
@"
TopicProductCollectionCellIdentifier
"
forIndexPath:
indexPath];
BaseModel *model = _dataSource[indexPath.row];
[cell
configViewWithModel:
model];
return
cell;
}
#
pragma mark
- UICollectionViewDelegate
- (
void
)
collectionView
:
(UICollectionView *)
collectionView
didSelectItemAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
ShopGoods *model = _dataSource[indexPath.row];
if
(_delegate && [_delegate
respondsToSelector:
@selector
(
didSelectGoodItem:
)]) {
[_delegate
didSelectGoodItem:
model];
}
}
@end
Back
|
FazBrowse Home
|
New Git URL