最后
你要问前端开发难不难,我就得说计算机领域里常说的一句话,这句话就是『难的不会,会的不难』,对于不熟悉某领域技术的人来说,因为不了解所以产生神秘感,神秘感就会让人感觉很难,也就是『难的不会』;当学会这项技术之后,知道什么什么技术能做到什么做不到,只是做起来花多少时间的问题而已,没啥难的,所以就是『会的不难』。
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
我特地针对初学者整理一套前端学习资料
参照CRProtocolManager做成私有pod
以上实施完毕,新建一个projectCRGoodsDetail
,新建2个类
CRGoodsDetailServiceProvide
CRGoodsDetailViewController
CRGoodsDetailServiceProvide
即是CRGoodsDetailServiceProtocol
的实现者 所以他依赖
CRGoodsDetailServiceProtocol
,因为商品详情模块需要跳转到订单确认页,所以他也依赖CRProtocolManager
。
添加Podfile文件编辑如下
source ‘https://github.com/sun6boys/CRRepositories.git’
source ‘https://github.com/CocoaPods/Specs.git’
target ‘CRGoodsDetail’ do
pod “CRProtocolManager”
pod “CRGoodsDetailServiceProtocol”
end
执行pod install --verbose --no-repo-update
最终CRGoodsDetailServiceProvide
实现代码如下
#import “CRGoodsDetailServiceProvide.h”
#import <CRGoodsDetailServiceProtocol/CRGoodsDetailServiceProtocol.h>
#import <CRProtocolManager/CRProtocolManager.h>
#import “CRGoodsDetailViewController.h”
@interface CRGoodsDetailServiceProvide()
@end
@implementation CRGoodsDetailServiceProvide
- (void)load
{
[CRProtocolManager registServiceProvide:[[self alloc] init] forProtocol:@protocol(CRGoodsDetailServiceProtocol)];
}
- (UIViewController )goodsDetailViewControllerWithGoodsId:(NSString)goodsId goodsName:(NSString *)goodsName
{
CRGoodsDetailViewController *goodsDetailVC = [[CRGoodsDetailViewController alloc] initWithGoodsId:goodsId goodsName:goodsName];
return goodsDetailVC;
}
@end
CRGoodsDetailViewController
实现代码如下
#import “CRGoodsDetailViewController.h”
@interface CRGoodsDetailViewController ()
@property (nonatomic, copy) NSString *goodsId;
@property (nonatomic, copy) NSString *goodsName;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UIButton *buyButton;
@end
@implementation CRGoodsDetailViewController
- (instancetype)initWithGoodsId:(NSString *)goodsId goodsName:(NSString *)goodsName
{
self = [super init];
if (self) {
_goodsId = goodsId;
_goodsName = goodsName;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = self.title;
[self.view addSubview:self.statusLabel];
[self.view addSubview:self.buyButton];
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.statusLabel.frame = CGRectMake(0, 0, 100, 20);
self.statusLabel.center = self.view.center;
self.buyButton.frame = CGRectMake(0, self.view.frame.size.height - 45, self.view.frame.size.width, 45);
}
#pragma mark - event
- (void)didClickBuyButton:(UIButton *)button
{
}
#pragma mark - getters
- (UILabel *)statusLabel
{
if (_statusLabel == nil) {
_statusLabel = [[UILabel alloc] init];
_statusLabel.textColor = [UIColor redColor];
_statusLabel.font = [UIFont systemFontOfSize:15.f];
_statusLabel.textAlignment = NSTextAlignmentCenter;
_statusLabel.text = @“暂未购买”;
}
return _statusLabel;
}
- (UIButton *)buyButton
{
if (_buyButton == nil) {
_buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_buyButton setTitle:@“立即购买” forState:UIControlStateNormal];
[_buyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_buyButton setBackgroundColor:[UIColor redColor]];
[_buyButton addTarget:self action:@selector(didClickBuyButton:) forControlEvents:UIControlEventTouchUpInside];
}
return _buyButton;
}
@end
把CRGoodsDetail
做成私有pod 记得编辑podspec文件的时候添加dependencyCRProtocolManager
CRGoodsDetailServiceProtocol
4.新建主项目MainProject
为了少建一个项目首页
模块我是直接放在主项目中的,按理首页
也应该是一个独立的pod.
首页
业务场景是,显示商品列表,点击某个商品进入该商品详情页. 所以他依赖CRGoodsDetailServiceProtocol
和CRProtocolManager
因为首页模块即是主项目所以他还得依赖CRGoodsDetail
最终首页核心代码如下
#pragma mark - event
- (void)didClickGoodsButton:(UIButton *)button
{
id goodsServiceProvide = [CRProtocolManager serviceProvideForProtocol:@protocol(CRGoodsDetailServiceProtocol)];
UIViewController *goodsDetailVC = [goodsServiceProvide goodsDetailViewControllerWithGoodsId:@“123” goodsName:@“农夫山泉矿泉水”];
[self.navigationController pushViewController:goodsDetailVC animated:YES];
}
5.确认订单模块
参照商品详情
新建确认订单业务入口pod 以及确认订单业务pod.和商品详情
有区别的是,提交订单完成后要回到商品详情
并且通知商品详情
用户已经购买,所以CRConfirmOrderServiceProtocol
接口定义如下
@protocol CRConfirmOrderServiceProtocol
- (UIViewController *)confirmOrderViewControllerWithGoodsId:(NSString *)goodsId sureComplete:(dispatch_block_t)sureComplete;
@end
前端面试题汇总
JavaScript
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
性能
linux
前端资料汇总
端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】](https://bbs.csdn.net/topics/618166371)**
性能
linux
前端资料汇总