My coding style~

代码展示:1.个人中心页面架构,2.商品列表页面架构

注:(源码全贴,建议扫视,如果你能够懂)

Mine Profile UI

images

个人中心的目录架构

images

viewModel

YBLProfileService.m

`

YBLProfileService ()
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
@property (nonatomic, weak ) YBLProfileViewController *VC;
@property (nonatomic, weak ) YBLProfileViewModel *viewModel;
@property (nonatomic, strong) UICollectionView *profileCollectionView;
@end
@implementation YBLProfileService
- (instancetype)initWithVC:(UIViewController *)VC ViewModel:(NSObject *)viewModel{
if (self = [super initWithVC:VC ViewModel:viewModel]) {
_VC = (YBLProfileViewController *)VC;
_viewModel = (YBLProfileViewModel *)viewModel;
WEAK
[RACObserve([YBLUserManageCenter shareInstance], userModel) subscribeNext:^(id x) {
STRONG
[self reloadCollectionViewNoAnimation];
}];
}
return self;
}
- (void)requestUserInfoData{
if ([YBLUserManageCenter shareInstance].isLoginStatus) {
WEAK
//判断是否有userionfos_id
if ([YBLUserManageCenter shareInstance].userModel.userinfo_id.length==0) {
//查询userionfos_id
[[YBLLoginViewModel siganlForGetUserInfoIds]subscribeError:^(NSError * _Nullable error) {
} completed:^{
STRONG
[self requestUserInfoModel];
}];
} else {
[self requestUserInfoModel];
}
} else {
[self reloadCollectionViewNoAnimation];
}
}
- (void)reloadCollectionViewNoAnimation{
[UIView performWithoutAnimation:^{
[self.profileCollectionView jsReloadData];
}];
}
- (void)requestUserInfoModel{
WEAK
[[YBLLoginViewModel siganlForGetUserInfos] subscribeError:^(NSError * _Nullable error) {
} completed:^{
STRONG
[self reloadCollectionViewNoAnimation];
}];
}
- (UICollectionView *)profileCollectionView{
if (!_profileCollectionView) {
CGFloat collectionWi = _VC.view.width/4;
UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
flowlayout.itemSize = CGSizeMake(collectionWi, 75);
flowlayout.minimumLineSpacing = 0;
flowlayout.minimumInteritemSpacing = 0;
_profileCollectionView = [[UICollectionView alloc] initWithFrame:[_VC.view bounds] collectionViewLayout:flowlayout];
_profileCollectionView.dataSource = self;
_profileCollectionView.delegate = self;
_profileCollectionView.alwaysBounceVertical = YES;
_profileCollectionView.showsVerticalScrollIndicator = NO;
_profileCollectionView.showsHorizontalScrollIndicator = NO;
_profileCollectionView.height = YBLWindowHeight - kBottomBarHeight;
_profileCollectionView.backgroundColor = [UIColor whiteColor];
[_profileCollectionView registerClass:NSClassFromString(@"YBLProfileRowItemCell") forCellWithReuseIdentifier:@"YBLProfileRowItemCell"];
[_profileCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionReusableView"];
[_profileCollectionView registerClass:[YBLProfileWaveHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"YBLProfileWaveHeaderView"];
[_VC.view addSubview:_profileCollectionView];
}
return _profileCollectionView;
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return self.viewModel.profile_cell_data_array.count;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.viewModel.profile_cell_data_array[section] count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = indexPath.row;
NSInteger section = indexPath.section;
YBLProfileRowItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YBLProfileRowItemCell"
forIndexPath:indexPath];
YBLProfileItemModel *model = self.viewModel.profile_cell_data_array[section][row];
[cell updateProfileItemModel:model];
WEAK
[[[cell.selectButton rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:cell.rac_prepareForReuseSignal] subscribeNext:^(__kindof UIControl * _Nullable x) {
STRONG
[self.viewModel pushVCWithItemModel:model WithNavigationVC:self.VC];
}];
return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
if([kind isEqualToString:UICollectionElementKindSectionHeader]){
if (indexPath.section==0) {
YBLProfileWaveHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:@"YBLProfileWaveHeaderView"
forIndexPath:indexPath];
WEAK
[headerView reloadHeaderData];
[[[headerView.setButton rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:headerView.rac_prepareForReuseSignal] subscribeNext:^(__kindof UIControl * _Nullable x) {
STRONG
YBLProdfileSettingViewController *settingVC = [YBLProdfileSettingViewController new];
[self.VC.navigationController pushViewController:settingVC animated:YES];
}];
[[[headerView.bgButton rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:headerView.rac_prepareForReuseSignal] subscribeNext:^(__kindof UIControl * _Nullable x) {
STRONG
if (![YBLMethodTools checkLoginWithVc:self.VC]) {
return ;
}
YBLAccountManageViewController *accountVC = [YBLAccountManageViewController new];
[self.VC.navigationController pushViewController:accountVC animated:YES];
}];
self.waveHeaderView = headerView;
return headerView;
} else {
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:@"UICollectionReusableView"
forIndexPath:indexPath];
headerView.backgroundColor = YBLViewBGColor;
return headerView;
}
}
return 0;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
if (section==0) {
return CGSizeMake(YBLWindowWidth, (YBLWindowHeight-kNavigationbarHeight)/3);
}
return CGSizeMake(YBLWindowWidth, space);
}
@end
`

YBLProfileViewModel

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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
@interface YBLProfileItemModel : NSObject
@property (nonatomic, copy ) NSString *profile_item_text;
@property (nonatomic, strong) NSNumber *profile_item_value;
@property (nonatomic, copy ) NSString *profile_item_self_vc;
@property (nonatomic) id profile_item_image_or_value;
@property (nonatomic, strong) NSNumber *profile_orderBadgeValue;
+ (YBLProfileItemModel *)getItemModelWithText:(NSString *)text
image:(id)image
value:(NSNumber *)value
self_vc:(NSString *)self_vc;
@end
@interface YBLProfileViewModel : NSObject
@property (nonatomic, strong) NSMutableArray *profile_cell_data_array;
- (void)pushVCWithItemModel:(YBLProfileItemModel *)itemModel WithNavigationVC:(UIViewController *)profileVC;
@end
.m:
@implementation YBLProfileItemModel
+ (YBLProfileItemModel *)getItemModelWithText:(NSString *)text
image:(id)image
value:(NSNumber *)value
self_vc:(NSString *)self_vc{
YBLProfileItemModel *model = [YBLProfileItemModel new];
model.profile_item_text = text;
model.profile_item_image_or_value = image;
model.profile_item_value = value;
model.profile_item_self_vc = self_vc;
return model;
}
@end
@interface YBLProfileViewModel ()
@property (nonatomic, strong) NSMutableArray *profile_section0_data_array;
@property (nonatomic, strong) NSMutableArray *profile_section1_data_array;
@property (nonatomic, strong) NSMutableArray *profile_section2_data_array;
@property (nonatomic, strong) NSMutableArray *section3_seller_data_array;
@property (nonatomic, strong) NSMutableArray *section3_buyer_data_array;
@end
@implementation YBLProfileViewModel
- (NSMutableArray *)profile_cell_data_array{
if (!_profile_cell_data_array) {
_profile_cell_data_array = [NSMutableArray array];
}
if (_profile_cell_data_array.count>0) {
[_profile_cell_data_array removeAllObjects];
}
[_profile_cell_data_array addObject:self.profile_section0_data_array];
[_profile_cell_data_array addObject:self.profile_section1_data_array];
[_profile_cell_data_array addObject:self.profile_section2_data_array];
return _profile_cell_data_array;
}
/**
* 我的订单
*
*/
- (NSMutableArray *)profile_section0_data_array{
if (!_profile_section0_data_array) {
_profile_section0_data_array = [NSMutableArray array];
[_profile_section0_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"我的订单"
image:@"profile_order"
value:@(0)
self_vc:@"YBLOrderViewController"]];
YBLProfileItemModel *dfModel = [YBLProfileItemModel getItemModelWithText:@"待付款"
image:@"profile_money"
value:@(1)
self_vc:@"YBLOrderViewController"];
[_profile_section0_data_array addObject:dfModel];
YBLProfileItemModel *dsModel = [YBLProfileItemModel getItemModelWithText:@"待收货"
image:@"profile_shouhuo"
value:@(2)
self_vc:@"YBLOrderViewController"];
[_profile_section0_data_array addObject:dsModel];
YBLProfileItemModel *pModel = [YBLProfileItemModel getItemModelWithText:@"待评价"
image:@"profile_pingjia"
value:@(3)
self_vc:@"YBLOrderCommentsViewController"];
[_profile_section0_data_array addObject:pModel];
}
[self handleNumberWithArray:_profile_section0_data_array index_section:0];
return _profile_section0_data_array;
}
- (void)handleNumberWithArray:(NSMutableArray *)array index_section:(NSInteger)index_section
{
NSInteger index = 0;
NSArray *valueCountArray;
NSInteger recordsCountOrNot = 0;
YBLUserInfoModel *infoModel = [YBLUserManageCenter shareInstance].userInfoModel;
if ([YBLUserManageCenter shareInstance].isLoginStatus) {
switch (index_section) {
case 0:
{
//待支付 待收货 待评价
recordsCountOrNot = 0;
valueCountArray = @[@(infoModel.not_payment_count.integerValue),@(infoModel.not_shipment_count.integerValue),@(infoModel.not_commented_count.integerValue)];
}
break;
case 1:
{
//商品关注 店铺关注 浏览记录
recordsCountOrNot = [YBLDBManage shareDB].getRecordsCount;
valueCountArray = @[@(infoModel.product_follows_count.integerValue),@(infoModel.shop_follows_count.integerValue),@(recordsCountOrNot)];
}
break;
default:
break;
}
} else {
valueCountArray = @[@(0),@(0),@(0)];
}
for (YBLProfileItemModel *pModel in array) {
if (index!=0) {
NSNumber *value = valueCountArray[index-1];
switch (index_section) {
case 0:
{
//待支付 待收货 待评价
pModel.profile_orderBadgeValue = value;
}
break;
case 1:
{
//商品关注 店铺关注 浏览记录
pModel.profile_item_image_or_value = value;
}
break;
default:
break;
}
}
index++;
}
}
/**
* 钱包
*
*/
- (NSMutableArray *)profile_section1_data_array{
if (!_profile_section1_data_array) {
_profile_section1_data_array = [NSMutableArray array];
[_profile_section1_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"我的钱包"
image:@"profile_money2"
value:nil
self_vc:@"YBLMyWalletsViewController"]];
[_profile_section1_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"商品关注"
image:@(0)
value:@(0)
self_vc:@"YBLFollowGoodsStoreListViewController"]];
[_profile_section1_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"店铺关注"
image:@(0)
value:@(1)
self_vc:@"YBLFollowGoodsStoreListViewController"]];
[_profile_section1_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"浏览记录"
image:@(0)
value:nil
self_vc:@"YBLFooterPrintsViewController"]];
}
[self handleNumberWithArray:_profile_section1_data_array index_section:1];
return _profile_section1_data_array;
}
/**
* 功能区
*
*/
- (NSMutableArray *)profile_section2_data_array{
if (!_profile_section2_data_array) {
_profile_section2_data_array = [NSMutableArray array];
}
if ([YBLUserManageCenter shareInstance].isLoginStatus&&[YBLUserManageCenter shareInstance].userType == UserTypeSeller&&[YBLUserManageCenter shareInstance].aasmState == AasmStateApproved) {
//dab
_profile_section2_data_array = self.section3_seller_data_array;
} else {
//xiaob
_profile_section2_data_array = self.section3_buyer_data_array;
}
return _profile_section2_data_array;
}
- (NSMutableArray *)section3_seller_data_array{
if (!_section3_seller_data_array) {
_section3_seller_data_array = [NSMutableArray array];
/**
* 大b
*/
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"我要采购"
image:@"iwantcaigou"
value:nil
self_vc:@"YBLFoundPurchaseViewController"]];
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"商品管理"
image:@"good_manage"
value:nil
self_vc:@"YBLGoodsManageVC"]];
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"订单管理"
image:@"order_manage"
value:@(-1)
self_vc:@"YBLOrderViewController"]];
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"商铺管理"
image:@"store_manage"
value:nil
self_vc:@"YBLStoreViewController"]];
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"营销管理"
image:@"marketing_manage"
value:nil
self_vc:@"YBLMarketingManageVC"]];
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"客户管理"
image:@"custom_manage"
value:nil
self_vc:@"YBLMineMillionMessageViewModel"]];
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"员工管理"
image:@"yuangong_manage"
value:nil
self_vc:@"YBLStaffManageVC"]];
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"分销管理"
image:@"fenxiao_manage"
value:nil
self_vc:@"YBLDistributionManageVC"]];
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"区域代理"
image:@"profile_daili"
value:nil
self_vc:@"YBLRegionalAgentViewController"]];
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"信用通"
image:@"vip_profile"
value:nil
self_vc:@"YBLOpenCreditsViewController"]];
/*
[_section3_seller_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"帮助"
image:@"my_help"
value:nil
self_vc:@"my_help"]];
*/
}
YBLProfileItemModel *orderManageModel = _section3_seller_data_array[2];
YBLUserInfoModel *infoModel = [YBLUserManageCenter shareInstance].userInfoModel;
if ([YBLUserManageCenter shareInstance].isLoginStatus) {
orderManageModel.profile_orderBadgeValue = infoModel.not_approved_count;
} else {
orderManageModel.profile_orderBadgeValue = @(0);
}
return _section3_seller_data_array;
}
- (NSMutableArray *)section3_buyer_data_array{
if (!_section3_buyer_data_array) {
_section3_buyer_data_array = [NSMutableArray array];
}
if (_section3_buyer_data_array.count>0) {
[_section3_buyer_data_array removeAllObjects];
}
/**
* 小b
*/
[_section3_buyer_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"我要赚钱"
image:@"iwantmoney"
value:nil
self_vc:@"YBLIWantMoneyViewController"]];
[_section3_buyer_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"区域代理"
image:@"profile_daili"
value:nil
self_vc:@"YBLRegionalAgentViewController"]];
if ([YBLUserManageCenter shareInstance].aasmState == AasmStateApproved) {
[_section3_buyer_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"VIP"
image:@"vip_profile"
value:nil
self_vc:@"YBLOpenCreditsViewController"]];
} else {
[_section3_buyer_data_array addObject:[YBLProfileItemModel getItemModelWithText:@"帮助"
image:@"my_help"
value:nil
self_vc:@"my_help"]];
if ((([YBLUserManageCenter shareInstance].aasmState == AasmStateRejected||[YBLUserManageCenter shareInstance].aasmState == AasmStateWaiteApproved)&&[YBLUserManageCenter shareInstance].userType == UserTypeSeller)||[YBLUserManageCenter shareInstance].userType == UserTypeGuest) {
[_section3_buyer_data_array insertObject:[YBLProfileItemModel getItemModelWithText:@"我要开店"
image:@"store_renzheng"
value:nil
self_vc:@"YBLIndustryScaleViewController"]
atIndex:0];
}
if ((([YBLUserManageCenter shareInstance].aasmState == AasmStateRejected||[YBLUserManageCenter shareInstance].aasmState == AasmStateWaiteApproved)&&[YBLUserManageCenter shareInstance].userType != UserTypeSeller)||[YBLUserManageCenter shareInstance].userType == UserTypeGuest) {
[_section3_buyer_data_array insertObject:[YBLProfileItemModel getItemModelWithText:@"采购认证"
image:@"shimingrenzheng"
value:nil
self_vc:@"YBLCertificationVC"]
atIndex:0];
}
}
return _section3_buyer_data_array;
}
- (void)pushVCWithItemModel:(YBLProfileItemModel *)itemModel WithNavigationVC:(UIViewController *)profileVC{
NSString *classname = itemModel.profile_item_self_vc;
Class class = NSClassFromString(classname);
if ([classname isEqualToString:@"my_help"]){
[YBLMethodTools pushWebVcFrom:profileVC URL:H5_URL_UseHelp_image title:@"注册认证流程"];
return;
} else if ([classname isEqualToString:@"YBLRegionalAgentViewController"]){
YBLRegionalAgentViewController *agenVC = [YBLRegionalAgentViewController new];
[profileVC.navigationController pushViewController:agenVC animated:YES];
return;
}
if (![YBLMethodTools checkLoginWithVc:profileVC]) {
return ;
}
#warning 未开发功能
if ([classname isEqualToString:@"YBLDistributionManageVC"]||
[classname isEqualToString:@"YBLIWantMoneyViewController"]||
!classname){
[SVProgressHUD showInfoWithStatus:@"此功能即将上线 \n 敬请期待!"];
return;
}
id classVC;
if ([classname isEqualToString:@"YBLFoundPurchaseViewController"]) {
YBLCategoryViewModel *wantPurchaseVC_viewModel = [YBLCategoryViewModel new];
wantPurchaseVC_viewModel.goodCategoryType = GoodCategoryTypeForPurchaseWithOutTabbar;
YBLAddGoodViewController *wantPurchaseVC = [[YBLAddGoodViewController alloc] init];
wantPurchaseVC.viewModel = wantPurchaseVC_viewModel;
classVC = wantPurchaseVC;
}else if ([classname isEqualToString:@"YBLStoreViewController"]){
YBLStoreViewModel *viewModel = [YBLStoreViewModel new];
viewModel.shopid = [YBLUserManageCenter shareInstance].userModel.userinfo_id;
viewModel.storeType = StoreTypePersonal;
YBLStoreViewController *storeVC = [[YBLStoreViewController alloc] init];
storeVC.viewModel = viewModel;
classVC = storeVC;
}
else if ([classname isEqualToString:@"YBLFollowGoodsStoreListViewController"]){
YBLFollowGoodsStoreViewModel *viewModel = [YBLFollowGoodsStoreViewModel new];
viewModel.currentFoundIndex = itemModel.profile_item_value.integerValue;
YBLFollowGoodsStoreListViewController *myVC = [YBLFollowGoodsStoreListViewController new];
myVC.viewModel = viewModel;
classVC = myVC;
}
else if ([classname isEqualToString:@"YBLGoodsManageVC"]){
YBLGoodsManageViewModel *viewModel = [YBLGoodsManageViewModel new];
YBLGoodsManageVC *goodManageVC = [YBLGoodsManageVC new];
goodManageVC.viewModel = viewModel;
classVC = goodManageVC;
} else if ([classname isEqualToString:@"YBLIndustryScaleViewController"]||[classname isEqualToString:@"YBLCertificationVC"]){
if ([YBLUserManageCenter shareInstance].aasmState == AasmStateUnknown||[YBLUserManageCenter shareInstance].aasmState == AasmStateInitial) {
YBLIndustryScaleViewController *indusVC = [YBLIndustryScaleViewController new];
if ([classname isEqualToString:@"YBLIndustryScaleViewController"]) {
indusVC.currentType = user_type_seller_key;
} else {
indusVC.currentType = user_type_buyer_key;
}
classVC = indusVC;
} else {
YBLTheResultViewController *resultVC = [YBLTheResultViewController new];
classVC = resultVC;
}
} else if ([classname isEqualToString:@"YBLOrderViewController"]){
YBLOrderViewModel *viewModel = [YBLOrderViewModel new];
OrderSource source;
if (itemModel.profile_item_value.intValue == -1) {
//dabi
source = OrderSourceSeller;
viewModel.currentFoundIndex = 0;
} else {
//xiaob
source = OrderSourceBuyer;
viewModel.currentFoundIndex = itemModel.profile_item_value.intValue;
}
viewModel.orderSource = source;
YBLOrderViewController *orderVC = [YBLOrderViewController new];
orderVC.viewModel = viewModel;
classVC = orderVC;
} else if ([classname isEqualToString:@"YBLMineMillionMessageViewModel"]) {
YBLMineMillionMessageViewModel *viewModel = [YBLMineMillionMessageViewModel new];
viewModel.millionType = MillionTypeMine;
YBLMineMillionMessageViewController *millionVc = [YBLMineMillionMessageViewController new];
millionVc.viewModel = viewModel;
classVC = millionVc;
} else {
classVC = [[class alloc] init];
}
[profileVC.navigationController pushViewController:classVC animated:YES];
}
@end

View

YBLProfileRowItemCell.h

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
@implementation YBLProfileRowItemCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self createUI];
}
return self;
}
- (void)createUI{
self.contentView.backgroundColor = [UIColor whiteColor];
self.selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.selectButton.frame = [self bounds];
[self.contentView addSubview:self.selectButton];
UIImageView *imageView = [[UIImageView alloc] init];
[self.contentView addSubview:imageView];
self.iconImageView = imageView;
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@25);
make.centerX.equalTo(self.mas_centerX);
make.centerY.equalTo(self.mas_centerY).with.offset(-12);
}];
self.badgeLabel = [[YBLBadgeLabel alloc] initWithFrame:CGRectZero];
self.badgeLabel.center = CGPointMake(self.width/2+10, self.height/2-30);
[self.contentView addSubview:self.badgeLabel];
UILabel *label = [[UILabel alloc] init];
label.font = YBLFont(16);
label.textColor = [UIColor redColor];
label.textAlignment = NSTextAlignmentCenter;
[self.contentView addSubview:label];
self.nummberLabel = label;
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(@0);
make.height.equalTo(@25);
make.centerY.equalTo(self.mas_centerY).with.offset(-12);
}];
UILabel *label1 = [[UILabel alloc] init];
label1.font = YBLFont(11);
label1.textColor = YBLColor(40, 40, 40, 1.0);
label1.textAlignment = NSTextAlignmentCenter;
[self.contentView addSubview:label1];
self.titleLabel = label1;
[label1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(@0);
make.height.equalTo(@25);
make.centerY.equalTo(self.mas_centerY).with.offset(12);
}];
}
- (void)updateProfileItemModel:(YBLProfileItemModel *)model{
if ([model.profile_item_image_or_value isKindOfClass:[NSString class]]) {
self.iconImageView.hidden = NO;
self.nummberLabel.hidden = YES;
self.iconImageView.image = [UIImage imageNamed:model.profile_item_image_or_value];
} else if ([model.profile_item_image_or_value isKindOfClass:[NSNumber class]]) {
self.iconImageView.hidden = YES;
self.nummberLabel.hidden = NO;
self.nummberLabel.text = [NSString stringWithFormat:@"%@",model.profile_item_image_or_value];
}
self.titleLabel.text = model.profile_item_text;
if (model.profile_orderBadgeValue&&model.profile_orderBadgeValue.integerValue!=0) {
self.badgeLabel.hidden = NO;
self.badgeLabel.bageValue = model.profile_orderBadgeValue.integerValue;
} else {
self.badgeLabel.hidden = YES;
}
}
@end

ViewController

YBLProfileViewController.m

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
@interface YBLProfileViewController ()
@property (nonatomic, strong) YBLProfileViewModel *viewModel;
@property (nonatomic, strong) YBLProfileService *service;
@end
@implementation YBLProfileViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.service requestUserInfoData];
[self.service.waveHeaderView.waveView startWaveAnimation];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:false];
[self.service.waveHeaderView.waveView stopWaveAnimation];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.viewModel = [YBLProfileViewModel new];
self.service = [[YBLProfileService alloc] initWithVC:self ViewModel:self.viewModel];
}

关于波浪的实现,可以去我另一篇文章看看

Good List

images

商品列表的目录架构

images

viewModel

YBLGoodListViewModel.h

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
@interface YBLGoodListViewModel : YBLTwotageMuduleViewModel
/**
* 关键字搜索
*/
@property (nonatomic, strong) NSString *keyWord;
/**
* 二级商品id
*/
@property (nonatomic, strong) NSString *category_id;
/**
* 店铺id
*/
@property (nonatomic, strong) NSString *userinfo_id;
/**
* 排序 顺序
*/
@property (nonatomic, assign) OrderSequence orderSequence;
/**
* 排序 字段
*/
@property (nonatomic, assign) OrderSequenceText orderSequenceText;
@property (nonatomic, assign) CGFloat lastPosition;
@property (nonatomic, assign) NSInteger page_list;
@property (nonatomic, assign) NSInteger page_count;
@property (nonatomic, strong) NSMutableArray *searchDataArray;
- (RACSignal *)siganlForSearchGoodsAgain:(BOOL)isNewSearch;
@end

YBLGoodListViewModel.m

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
@implementation YBLGoodListViewModel
- (NSMutableArray *)searchDataArray{
if (!_searchDataArray) {
_searchDataArray = [NSMutableArray array];
}
return _searchDataArray;
}
- (RACSignal *)siganlForSearchGoodsAgain:(BOOL)isNewSearch{
RACReplaySubject *subject = [RACReplaySubject subject];
/**
* 默认综合-->升序
*/
NSString *orderField = @"sale_order_count";
NSString *orderAsc = nil;
switch (self.orderSequenceText) {
case OrderSequenceTextComposite:
// orderField = nil;
break;
case OrderSequenceTextSaleCount:
orderField = @"sale_order_count";
break;
case OrderSequenceTextPrice:
orderField = @"price";
break;
default:
break;
}
switch (self.orderSequence) {
case OrderSequenceDescending:
orderAsc = @"desc";
break;
case OrderSequenceAscending:
orderAsc = @"asc";
break;
default:
break;
}
if (isNewSearch) {
self.page_list = 0;
[YBLLogLoadingView showInWindow];
}
self.page_list++;
[[self siganlForGoodListCategoryID:self.category_id
userinfoID:self.userinfo_id
searchText:self.keyWord
orderField:orderField
orderAsc:orderAsc
page:self.page_list] subscribeNext:^(id x) {
NSArray *dataArray = [NSArray yy_modelArrayWithClass:[YBLGoodModel class] json:x[@"products"]];
self.page_count = ceil([x[@"total_count"] integerValue]/page_size);
if (isNewSearch) {
[YBLLogLoadingView dismissInWindow];
[self.searchDataArray removeAllObjects];
}
NSMutableArray *indexps = [YBLMethodTools getRowAppendingIndexPathsWithIndex:self.searchDataArray.count appendingCount:dataArray.count inSection:0];
if (dataArray.count!=0) {
[self.searchDataArray addObjectsFromArray:dataArray];
self.isNoMoreData = NO;
} else {
self.isNoMoreData = YES;
}
[subject sendNext:indexps];
[subject sendCompleted];
} error:^(NSError * _Nullable error) {
if (self.page_list>0) {
self.page_list--;
}
[subject sendError:error];
}];
return subject;
}
@end

YBLGoodListService.m

Main Method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
- (instancetype)initWithVC:(UIViewController *)VC ViewModel:(NSObject *)viewModel{
if (self = [super initWithVC:VC ViewModel:viewModel]) {
_viewModel = (YBLGoodListViewModel *)viewModel;
_Vc = (YBLGoodListViewController *)VC;
[self createNavigationBar];
[self requestSearchDataAgain:YES];
}
return self;
}

这就是我的编码套路,这样写的好处不用多言,单元测试、代码复用、继承扩展、诸此,待你撸码的时候才会发现多好用,以上你首先多RAC有些了解。欢迎纠正,补充,建议,共同进步~

坚持原创技术分享,您的支持将鼓励我继续创作!