2024年Web前端最全iOS组件化方案-总结第一篇,快速前端开发

最后

你要问前端开发难不难,我就得说计算机领域里常说的一句话,这句话就是『难的不会,会的不难』,对于不熟悉某领域技术的人来说,因为不了解所以产生神秘感,神秘感就会让人感觉很难,也就是『难的不会』;当学会这项技术之后,知道什么什么技术能做到什么做不到,只是做起来花多少时间的问题而已,没啥难的,所以就是『会的不难』。

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

我特地针对初学者整理一套前端学习资料

前端路线图

vue.js的36个技巧

参照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.

首页业务场景是,显示商品列表,点击某个商品进入该商品详情页. 所以他依赖CRGoodsDetailServiceProtocolCRProtocolManager因为首页模块即是主项目所以他还得依赖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

前端资料汇总

  • 9
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值