Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d563b74

Browse files
终结MVVM Without RAC 的实践Demo。
1 parent da57798 commit d563b74

File tree

87 files changed

+3166
-699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+3166
-699
lines changed

‎MHDevelopExample/MHDevelopExample.xcodeproj/project.pbxproj‎

Lines changed: 400 additions & 90 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// SUGoods+SUAttributedString.h
3+
// MHDevelopExample
4+
//
5+
// Created by senba on 2017年6月16日.
6+
// Copyright © 2017年 CoderMikeHe. All rights reserved.
7+
//
8+
9+
#import "SUGoods.h"
10+
11+
@interface SUGoods (SUAttributedString)
12+
13+
/**
14+
* 商品价格的富文本
15+
*/
16+
- (NSMutableAttributedString *)su_goodsPriceAttributedString;
17+
18+
/**
19+
* 商品原价格的富文本
20+
*/
21+
- (NSMutableAttributedString *)su_goodsOPriceAttributedString;
22+
23+
/**
24+
* 全新+标题
25+
*/
26+
- (NSMutableAttributedString *)su_goodsTitleAttributedString;
27+
28+
@end
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// SUGoods+SUAttributedString.m
3+
// MHDevelopExample
4+
//
5+
// Created by senba on 2017年6月16日.
6+
// Copyright © 2017年 CoderMikeHe. All rights reserved.
7+
//
8+
9+
#import "SUGoods+SUAttributedString.h"
10+
11+
@implementation SUGoods (SUAttributedString)
12+
/**
13+
* 商品价格的富文本
14+
*/
15+
- (NSMutableAttributedString *)su_goodsPriceAttributedString{
16+
17+
if(!MHStringIsNotEmpty(self.price)) return nil;
18+
19+
if (self.price.floatValue<=.000001f) return nil;
20+
21+
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"\%@", self.price]];
22+
23+
/// 设置所有字符串的富文本
24+
[attrString setAttributes:@{NSForegroundColorAttributeName:SUGlobalLightRedColor,
25+
NSFontAttributeName:MHMediumFont(22.0f)
26+
} range:NSMakeRange(0, attrString.string.length)];
27+
// 设置第一个\的字体大小
28+
NSRange rmbRange = NSMakeRange(0, 1);
29+
[attrString yy_setFont:MHMediumFont(14.0f) range:rmbRange];
30+
[attrString yy_setColor:SUGlobalLightRedColor range:rmbRange];
31+
32+
return attrString.copy;
33+
}
34+
35+
/**
36+
* 商品原价格的富文本
37+
*/
38+
- (NSMutableAttributedString *)su_goodsOPriceAttributedString{
39+
if(MHStringIsNotEmpty(self.oPrice) && self.oPrice.floatValue>.0000001)
40+
{
41+
NSMutableAttributedString *oPriceAttr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"原价%@",self.oPrice]];
42+
oPriceAttr.yy_font = MHRegularFont_12;
43+
oPriceAttr.yy_color = SUGlobalShadowGrayTextColor;
44+
return oPriceAttr.copy;
45+
}
46+
return nil;
47+
}
48+
49+
/**
50+
* 全新+标题
51+
*/
52+
- (NSMutableAttributedString *)su_goodsTitleAttributedString{
53+
// 是否全新
54+
NSString *goodsTitle = [self valueForKeyPath:@"title"];
55+
if (!MHStringIsNotEmpty(goodsTitle) && !self.isBrandNew) return nil;
56+
57+
NSString *tempStr = (self.isBrandNew)?[NSString stringWithFormat:@" %@",goodsTitle]:goodsTitle;
58+
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:tempStr];
59+
attr.yy_font = MHMediumFont(15.0f);
60+
attr.yy_color = MHGlobalShadowBlackTextColor;
61+
62+
if (self.isBrandNew) {
63+
NSTextAttachment *attach = [[NSTextAttachment alloc] init];
64+
attach.image = [UIImage imageNamed:@"su_goods_home_new"];
65+
attach.bounds = CGRectMake(0, -2.5, attach.image.size.width, attach.image.size.height);
66+
NSAttributedString *imageAttr = [NSAttributedString attributedStringWithAttachment:attach];
67+
[attr insertAttributedString:imageAttr atIndex:0];
68+
return attr;
69+
}
70+
return attr;
71+
72+
}
73+
@end

‎MHDevelopExample/MHDevelopExample/Classes/MVC&MVVM/Base/BaseModel/SUGoods.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ typedef NS_ENUM(NSUInteger, SUGoodsExpressType) {
6868

6969

7070

71+
72+
73+
74+
7175
//// 以下 MVC使用的场景,如果使用MVVM的请自行ignore
7276
//// 辅助属性
7377
/// 商品图片UrlString
@@ -85,7 +89,7 @@ typedef NS_ENUM(NSUInteger, SUGoodsExpressType) {
8589
@property (nonatomic, readonly, copy) NSAttributedString *goodsOPriceAttributedString;
8690

8791
/// 全新+title
88-
@property (nonatomic, readwrite, copy) NSAttributedString *goodsTitleAttributedString;
92+
@property (nonatomic, readonly, copy) NSAttributedString *goodsTitleAttributedString;
8993

9094
//// 以上 MVC使用的场景,如果使用MVVM的请自行ignore
9195
@end

‎MHDevelopExample/MHDevelopExample/Classes/MVC&MVVM/Base/BaseView/SUGoodsCell.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@
2020
/**
2121
* 图片被点击
2222
*/
23-
typedef void(^SUGoodsCellPictureClickedHandler)(SUGoodsCell *goodsCell, NSInteger index);
23+
typedef void(^SUGoodsCellPictureClickedHandler)(SUGoodsCell *goodsCell);
2424
/**
2525
* 头像被点击
2626
*/
27-
typedef void(^SUGoodsCellAvatarClickedHandler)(SUGoodsCell *goodsCell , NSString *userId);
27+
typedef void(^SUGoodsCellAvatarClickedHandler)(SUGoodsCell *goodsCell);
2828

2929
/**
3030
* 位置被点击
3131
*/
32-
typedef void(^SUGoodsCellLocationClickedHandler)(SUGoodsCell *goodsCell , NSString *locationAreaName);
32+
typedef void(^SUGoodsCellLocationClickedHandler)(SUGoodsCell *goodsCell);
3333

3434
/**
3535
* 留言被点击
3636
*/
37-
typedef void(^SUGoodsCellReplyClickedHandler)(SUGoodsCell *goodsCell , NSString *goodsId);
37+
typedef void(^SUGoodsCellReplyClickedHandler)(SUGoodsCell *goodsCell);
3838

3939
/**
4040
* 点赞被点击
4141
*/
42-
typedef void(^SUGoodsCellThumbClickedHandler)(SUGoodsCell *goodsCell , NSString *goodsId);
42+
typedef void(^SUGoodsCellThumbClickedHandler)(SUGoodsCell *goodsCell);
4343

4444
//// 以上 MVC 和 MVVM without RAC 的事件回调的使用的场景,如果使用MVVM With RAC的请自行ignore
4545

‎MHDevelopExample/MHDevelopExample/Classes/MVC&MVVM/Base/BaseView/SUGoodsCell.m‎

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#import "SUGoodsImageCell.h"
1616

1717

18-
//#import "SUGoodsHomeItemViewModel.h"
18+
#import "SUGoodsItemViewModel.h"
1919

2020

2121
@interface SUGoodsCell()<
@@ -60,9 +60,10 @@ @interface SUGoodsCell()<
6060
/// 点赞按钮
6161
@property (weak, nonatomic) IBOutlet UIButton *thumbBtn;
6262

63-
63+
//// 以下 MVVM使用的场景,如果使用MVC的请自行ignore
6464
/// viewModle
65-
//@property (nonatomic, readwrite, strong) SUGoodsHomeItemViewModel *viewModel;
65+
@property (nonatomic, readwrite, strong) SUGoodsItemViewModel *viewModel;
66+
//// 以上 MVVM使用的场景,如果使用MVC的请自行ignore
6667
@end
6768

6869
@implementation SUGoodsCell
@@ -109,7 +110,7 @@ - (void)awakeFromNib{
109110
self.flowLayout.itemSize = CGSizeMake(itemWH, itemWH);
110111
self.optimalProductCollectionView.backgroundColor = [UIColor whiteColor];
111112

112-
// ---add Action
113+
// ---add Action ---
113114
//// 使用MVC 和 MVVM without RAC 的事件回调
114115
[self _addActionDealForMVCOrMVVMWithoutRAC];
115116

@@ -118,53 +119,57 @@ - (void)awakeFromNib{
118119

119120
}
120121

122+
// 以下 MVVM使用的场景,如果使用MVC的请自行ignore
123+
#pragma mark - bind data
124+
- (void)bindViewModel:(SUGoodsItemViewModel *)viewModel
125+
{
126+
self.viewModel = viewModel;
127+
128+
/// 头像
129+
[MHWebImageTool setImageWithURL:viewModel.goods.avatar placeholderImage:placeholderUserIcon() imageView:self.userHeadImageView];
130+
131+
/// 昵称
132+
self.userNameLabel.text = viewModel.goods.nickName;
133+
self.realNameIcon.hidden = !viewModel.goods.iszm;
134+
/// 发布时间
135+
self.publishTimeLabel.text = viewModel.goodsPublishTime;
136+
137+
/// 照片
138+
self.imageURLs = viewModel.imagesUrlStrings;
139+
140+
/// 卖价
141+
self.priceLabel.attributedText = viewModel.goodsPriceAttributedString;
142+
self.priceLabel.frame = viewModel.priceLalelFrame;
143+
144+
/// 原价
145+
self.oldPriceLabel.attributedText = viewModel.goodsOPriceAttributedString;
146+
self.oldPriceLabel.frame = viewModel.oPriceLalelFrame;
147+
148+
/// 运费
149+
self.extraFee.text = viewModel.freightExplain;
150+
self.extraFee.frame = viewModel.freightageLalelFrame;
151+
[self.extraFee hyb_addCornerRadius:2];
152+
/// 数量
153+
self.countLabel.text = viewModel.number;
154+
155+
/// 主题
156+
self.goodsTitleLabel.attributedText = viewModel.goodsTitleAttributedString;
157+
158+
/// 描述
159+
self.contentLabel.text = viewModel.goods.goodsDescription;
160+
161+
/// 位置
162+
[self.GPSBtn setTitle:viewModel.goods.locationAreaName forState:UIControlStateNormal];
163+
164+
/// 回复数
165+
[self.replyBtn setTitle:viewModel.goods.messages forState:UIControlStateNormal];
166+
167+
/// 点赞数
168+
[self.thumbBtn setTitle:viewModel.goods.likes forState:UIControlStateNormal];
169+
self.thumbBtn.selected = viewModel.goods.isLike;
121170

122-
//#pragma mark - bind data
123-
//- (void)bindViewModel:(SUGoodsHomeItemViewModel *)viewModel
124-
//{
125-
// self.viewModel = viewModel;
126-
//
127-
// /// 头像
128-
// [MHWebImageTool setImageWithURL:viewModel.avatar placeholderImage:placeholderUserIcon() imageView:self.userHeadImageView];
129-
//
130-
// /// 昵称
131-
// self.userNameLabel.text = viewModel.nickname;
132-
// self.realNameIcon.hidden = !viewModel.iszm;
133-
// /// 发布时间
134-
// self.publishTimeLabel.text = viewModel.publishTime;
135-
//
136-
// /// 照片
137-
// self.imageURLs = viewModel.imageURLs;
138-
//
139-
// /// 卖价
140-
// self.priceLabel.attributedText = viewModel.price;
141-
// self.priceLabel.frame = viewModel.priceLalelFrame;
142-
//
143-
// /// 原价
144-
// self.oldPriceLabel.attributedText = viewModel.oPrice;
145-
// self.oldPriceLabel.frame = viewModel.oPriceLalelFrame;
146-
//
147-
// /// 运费
148-
// self.extraFee.text = viewModel.freightExplain;
149-
// self.extraFee.frame = viewModel.freightageLalelFrame;
150-
// [self.extraFee hyb_addCornerRadius:2];
151-
// /// 数量
152-
// self.countLabel.text = viewModel.number;
153-
//
154-
// /// 主题
155-
// self.goodsTitleLabel.attributedText = viewModel.titleAttr;
156-
//
157-
// /// 描述
158-
// self.contentLabel.text = viewModel.goodsDescription;
159-
//
160-
// /// 位置
161-
// [self.GPSBtn setTitle:viewModel.locationName forState:UIControlStateNormal];
162-
//
163-
// /// 留言数量
164-
// [self.replyBtn setAttributedTitle:viewModel.messages forState:UIControlStateNormal];
165-
//
166-
//}
167-
171+
}
172+
//// 以上 MVVM使用的场景,如果使用MVC的请自行ignore
168173

169174

170175

@@ -234,27 +239,27 @@ - (void)_addActionDealForMVCOrMVVMWithoutRAC
234239
@weakify(self);
235240
[self.userHeadImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] bk_initWithHandler:^(UIGestureRecognizer *sender, UIGestureRecognizerState state, CGPoint location) {
236241
@strongify(self);
237-
!self.avatarClickedHandler?:self.avatarClickedHandler(self , self.goodsFrame.goods.userId);
242+
!self.avatarClickedHandler?:self.avatarClickedHandler(self);
238243
}]];
239244

240245
/// 位置被点击
241246
[self.GPSBtn bk_addEventHandler:^(id sender) {
242247
@strongify(self);
243-
!self.locationClickedHandler?:self.locationClickedHandler(self , self.goodsFrame.goods.locationAreaName);
248+
!self.locationClickedHandler?:self.locationClickedHandler(self);
244249
} forControlEvents:UIControlEventTouchUpInside];
245250

246251

247252
/// 回复按钮被点击
248253
[self.replyBtn bk_addEventHandler:^(id sender) {
249254
@strongify(self);
250-
!self.replyClickedHandler?:self.replyClickedHandler(self , self.goodsFrame.goods.goodsId);
255+
!self.replyClickedHandler?:self.replyClickedHandler(self);
251256
} forControlEvents:UIControlEventTouchUpInside];
252257

253258

254259
/// 收藏按钮被点击
255260
[self.thumbBtn bk_addEventHandler:^(id sender) {
256261
@strongify(self);
257-
!self.thumbClickedHandler?:self.thumbClickedHandler(self , self.goodsFrame.goods.goodsId);
262+
!self.thumbClickedHandler?:self.thumbClickedHandler(self);
258263
} forControlEvents:UIControlEventTouchUpInside];
259264
}
260265
//// 以上 MVC 和 MVVM without RAC 的事件回调的使用的场景,如果使用MVVM With RAC的请自行ignore

‎MHDevelopExample/MHDevelopExample/Classes/MVC&MVVM/Base/BaseView/SUGoodsHeaderView.m‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ - (void)awakeFromNib
1515
[super awakeFromNib];
1616

1717
/// Setting the background color on UITableViewHeaderFooterView has been deprecated. Please use contentView.backgroundColor instead.
18+
self.backgroundColor = SUGlobalGrayBackgroundColor;
1819
self.contentView.backgroundColor = SUGlobalGrayBackgroundColor;
1920
}
2021

‎MHDevelopExample/MHDevelopExample/Classes/MVC&MVVM/Base/BaseView/SUGoodsHeaderView.xib‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</constraints>
4343
</view>
4444
</subviews>
45-
<color key="backgroundColor" white="0.0"alpha="0.0" colorSpace="calibratedWhite"/>
45+
<color key="backgroundColor" red="0.93333333333333335"green="0.93725490196078431"blue="0.95686274509803915"alpha="0.0" colorSpace="calibratedRGB"/>
4646
<constraints>
4747
<constraint firstItem="k38-LX-ZtN" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="2uJ-BB-sgZ"/>
4848
<constraint firstAttribute="bottom" secondItem="k38-LX-ZtN" secondAttribute="bottom" id="HdB-o6-P7a"/>

‎MHDevelopExample/MHDevelopExample/Classes/MVC&MVVM/Base/BaseViewController/Base/SUBaseViewController.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Created by senba on 2017年6月12日.
66
// Copyright © 2017年 CoderMikeHe. All rights reserved.
7-
// 最基础的UIViewController
7+
// 最基础的UIViewController -- C
88

99
#import <UIKit/UIKit.h>
1010

‎MHDevelopExample/MHDevelopExample/Classes/MVC&MVVM/Base/BaseViewController/Base/SUBaseViewController.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ - (void)viewDidLoad {
2020
self.automaticallyAdjustsScrollViewInsets = NO;
2121
self.extendedLayoutIncludesOpaqueBars = YES;
2222
/// backgroundColor
23-
self.view.backgroundColor = MHColorFromHexString(@"#EEEFF4");
23+
self.view.backgroundColor = SUGlobalGrayBackgroundColor;
2424
}
2525

2626
#pragma mark - Orientation

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /