源代码下载地址:http://code4app.com/ios/55655def933bf09d328b5141

此源代码从中学到以下四个知识点

第一:关于右边只有一个被选中的效果展现,左边部分代码内容,其是一个列表的形式,橙色为一个视图的效果,当没有被选中时则隐藏起来,这边默认第一个被选中;

单元格BADockCell.h

#import <UIKit/UIKit.h>
@interface BADockCell : UITableViewCell
@property (nonatomic ,weak) NSString *categoryText;
@property (nonatomic ,weak) UILabel *category;
@property (nonatomic ,weak) UIView *viewShow1;
+ (instancetype)cellWithTableView:(UITableView *)tableView;
@end .m文件内容: #import "BADockCell.h"
#import "Header.h"
@interface BADockCell ()
@end @implementation BADockCell -(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UILabel *category =[[UILabel alloc]initWithFrame:(CGRect){,,,}];
[self.contentView addSubview:category];
_category=category; UIView *viewShow =[[UIView alloc]initWithFrame:(CGRect){,49.5,,0.5}];
viewShow.backgroundColor=[UIColor blackColor];
viewShow.alpha=0.4;
[self.contentView addSubview:viewShow];
UIView *viewShow1 =[[UIView alloc]initWithFrame:(CGRect){,,,}];
viewShow1.backgroundColor=UIColorRGBA(, , , );
[self.contentView addSubview:viewShow1]; viewShow1.hidden=YES;
_viewShow1=viewShow1;
}
return self;
} -(void)setCategoryText:(NSString *)categoryText
{
_category.text=categoryText;
_category.textAlignment=NSTextAlignmentCenter;
_category.font=Font(); } + (instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *ID = @"BADockCell";
BADockCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[BADockCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
//取消选中状态
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return cell;
}
@end
注意:+ (instancetype)cellWithTableView:(UITableView *)tableView在这边对CELL进行注册,然后在UITableView外面加载列时进行调用BADockCell *cell =[BADockCell cellWithTableView:tableView];

. h文件的内容(继承于UITableView)

#import <UIKit/UIKit.h>
@protocol DockTavleViewDelegate <NSObject>
-(void)dockClickindexPathRow:(NSMutableArray *)row index:(NSIndexPath *)index indeXPath:(NSIndexPath *)indexPath;
@end @interface BAWineShoppingDockTavleView : UITableView
@property (nonatomic ,strong) NSMutableArray *dockArray;
@property (weak ,nonatomic) id <DockTavleViewDelegate>dockDelegate;
@end .m文件的内容 #import "BAWineShoppingDockTavleView.h"
#import "BADockCell.h"
#import "Header.h"
@interface BAWineShoppingDockTavleView ()<UITableViewDelegate,UITableViewDataSource> @property (nonatomic ,strong) NSIndexPath *path;
@property (nonatomic ,assign) BOOL is;
@end @implementation BAWineShoppingDockTavleView -(id)initWithFrame:(CGRect)frame
{
self =[super initWithFrame:frame];
if (self) {
self.dataSource=self;
self.delegate=self;
}
return self;
} -(void)layoutSubviews
{
[super layoutSubviews];
//只让它在初始化运行 运行一次_is就不为空了 给表格进行绑定
if(!_is)
{
NSInteger selectedIndex = ;
NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:selectedIndex inSection:];
[self tableView:self didSelectRowAtIndexPath:selectedIndexPath];
_is=YES;
}
} -(void)setDockArray:(NSMutableArray *)dockArray
{
_dockArray=dockArray;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dockArray.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//这样方式的加载内容不错
BADockCell *cell =[BADockCell cellWithTableView:tableView];
cell.categoryText=_dockArray[indexPath.row][@"dockName"];
cell.backgroundColor=[UIColor whiteColor];
return cell;
} -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_path!=nil) {
NSLog(@"上一个被选中%zd",_path.row);
BADockCell *cell = (BADockCell *)[tableView cellForRowAtIndexPath:_path];
cell.backgroundColor=[UIColor whiteColor];
cell.category.textColor=[UIColor blackColor];
cell.viewShow1.hidden=YES;
}
if ([_dockDelegate respondsToSelector:@selector(dockClickindexPathRow: index: indeXPath:)]) {
[_dockDelegate dockClickindexPathRow:_dockArray[indexPath.row][@"right"] index:_path indeXPath:indexPath];
}
//取消选中颜色 BADockCell *cell = (BADockCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.category.textColor=UIColorRGBA(, , , );
cell.backgroundColor=UIColorRGBA(, , , );
cell.viewShow1.hidden=NO;
_path=indexPath;
NSLog(@"选中%zd",_path.row);
}
@end

注意:对于_is变量只是用于第一次默认加载时,判断它并让其对第一个进行选中,最后进行赋值,这样就可以避免在表格绑定列时再进行判断的问题,而_path变量则是为了把选中的值赋给它,在didSelectRowAtIndexPath中一开始对它进行是否为空的判断,这样就可以清理掉上一次的选中;

第二:关于左边选中后右边进行更新,它还有一个效果是右边会刷新从顶部回到第一条,代码简单如下

@property (nonatomic ,strong) BAWineShoppingDockTavleView *dockTavleView;
@property (nonatomic ,strong) BARightTableView *rightTableView;
@property (nonatomic ,strong) NSMutableArray *dockArray;
@property (nonatomic ,strong) NSMutableArray *offsArray; -(void)viewDidLoad
{
BAWineShoppingDockTavleView *dockTavleView =[[BAWineShoppingDockTavleView alloc]initWithFrame:(CGRect){,,,kWindowHeight-}];
dockTavleView.rowHeight=;
dockTavleView.dockDelegate=self;
dockTavleView.backgroundColor=UIColorRGBA(, , , );
[dockTavleView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.view addSubview:dockTavleView];
_dockTavleView =dockTavleView; BARightTableView *rightTableView =[[BARightTableView alloc]initWithFrame:(CGRect){,,kWindowWidth-,kWindowHeight-}];
rightTableView.rowHeight=;
rightTableView.rightDelegate=self;
rightTableView.backgroundColor=UIColorRGBA(, , , );
[rightTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.view addSubview:rightTableView];
_rightTableView=rightTableView;
} -(void)dockClickindexPathRow:(NSMutableArray *)array index:(NSIndexPath *)index indeXPath:(NSIndexPath *)indexPath
{
[_rightTableView setContentOffset:_rightTableView.contentOffset animated:NO];
_offsArray[index.row] =NSStringFromCGPoint(_rightTableView.contentOffset);
_rightTableView.rightArray=array;
[_rightTableView reloadData];
CGPoint point=CGPointFromString([_offsArray objectAtIndex:indexPath.row]);
[_rightTableView setContentOffset:point];
}

第三:关于右边列增加或减少数量时,下面部分变化则是运用的回调的方式实现;在单元列中定义的一个回调,在右边的表格上进行一个委托,然后在主页面上进行实现变化的内容;

右边列.h文件:

#import <UIKit/UIKit.h>

@interface BARightCell : UITableViewCell
@property (nonatomic ,strong) NSMutableDictionary *rightData;
+ (instancetype)cellWithTableView:(UITableView *)tableView;
@property (nonatomic , copy) void (^TapActionBlock)(NSInteger pageIndex ,NSInteger money ,NSString *key);
@end 右边列.m文件(主要代码): -(void)wineRightClick
{
int NumberInt =[_wineQuantity.text intValue];
if (NumberInt ==) {
return;
}
++NumberInt; _wineQuantity.text =[NSString stringWithFormat:@"%d",NumberInt];
_rightData[@"Quantity"] = _wineQuantity.text;
_TapActionBlock([ _rightData[@"Quantity"] integerValue],[_rightData[@"money"] integerValue] ,_rightData[@"ProductID"]);
} -(void)wineLeftClick
{
int NumberInt =[_wineQuantity.text intValue];
if (NumberInt ==) {
return;
}
--NumberInt;
_wineQuantity.text =[NSString stringWithFormat:@"%d",NumberInt];
_rightData[@"Quantity"] = _wineQuantity.text;
_TapActionBlock([ _rightData[@"Quantity"] integerValue],[_rightData[@"money"] integerValue],_rightData[@"ProductID"]);
if (NumberInt ==) {
return;
} } 右边表格的.h: @protocol RightTableViewDelegate <NSObject>
-(void)quantity:(NSInteger)quantity money:(NSInteger)money key:(NSString *)key;
@end
@interface BARightTableView : UITableView
@property (nonatomic ,strong) NSMutableArray *rightArray;
@property (nonatomic ,weak) id<RightTableViewDelegate>rightDelegate;
@end 右边表格的.m: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BARightCell *cell =[BARightCell cellWithTableView:tableView];
cell.TapActionBlock=^(NSInteger pageIndex ,NSInteger money,NSString *key){
if ([self.rightDelegate respondsToSelector:@selector(quantity:money:key:)]) {
[self.rightDelegate quantity:pageIndex money:money key:key];
}
};
cell.backgroundColor=UIColorRGBA(, , , );
cell.rightData=_rightArray[indexPath.row];
return cell;
} 主页面实现在变化(rightTableView.rightDelegate=self): -(void)quantity:(NSInteger)quantity money:(NSInteger)money key:(NSString *)key
{
NSInteger addend =quantity *money; [_dic setObject:[NSString stringWithFormat:@"%ld",addend] forKey:key];
//得到词典中所有KEY值
NSEnumerator * enumeratorKey = [_dic keyEnumerator];
//遍历所有KEY的值
NSInteger total=;
NSInteger totalSingularInt=;
for (NSObject *object in enumeratorKey) {
total+=[_dic[object] integerValue];
if ([_dic[object] integerValue] !=) {
totalSingularInt +=;
_totalSingular.hidden=NO;
}
}
if (totalSingularInt==) {
_totalSingular.hidden=YES;
_bottomLabel.backgroundColor=[UIColor lightGrayColor];
_bottomLabel.userInteractionEnabled=NO;
_bottomLabel.text=@"请选购";
}else
{
_bottomLabel.backgroundColor=[UIColor clearColor];
_bottomLabel.userInteractionEnabled=YES;
_bottomLabel.text=@"去结算";
}
_totalSingular.text=[NSString stringWithFormat:@"%ld",totalSingularInt];
_totalPrice.text=[NSString stringWithFormat:@"¥%ld",total]; }

第四:关于页面的圆角样式效果

BALabel *bottomLabel =[[BALabel alloc]initWithFrame:(CGRect){kWindowWidth--,/-/,,}];
bottomLabel.text=@"请选购";
bottomLabel.textColor=[UIColor whiteColor];
bottomLabel.textAlignment=NSTextAlignmentCenter;
bottomLabel.font=Font();
bottomLabel.backgroundColor=[UIColor lightGrayColor];
bottomLabel.layer.masksToBounds=YES;
bottomLabel.layer.cornerRadius=;
bottomLabel.layer.borderWidth = ;
bottomLabel.userInteractionEnabled=NO;
[bottomLabel addTarget:self action:@selector(bottomLabelClick) forControlEvents:BALabelControlEventTap];
bottomLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
[bottomView addSubview:bottomLabel];

Purchase购物车实例分析的更多相关文章

  1. 068——VUE中vuex的使用场景分析与state购物车实例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. RPC原理及RPC实例分析

    在学校期间大家都写过不少程序,比如写个hello world服务类,然后本地调用下,如下所示.这些程序的特点是服务消费方和服务提供方是本地调用关系. 1 2 3 4 5 6 public class ...

  3. java基础学习05(面向对象基础01--类实例分析)

    面向对象基础01(类实例分析) 实现的目标 1.如何分析一个类(类的基本分析思路) 分析的思路 1.根据要求写出类所包含的属性2.所有的属性都必须进行封装(private)3.封装之后的属性通过set ...

  4. (转)实例分析:MySQL优化经验

    [IT专家网独家]同时在线访问量继续增大,对于1G内存的服务器明显感觉到吃力,严重时甚至每天都会死机,或者时不时的服务器卡一下,这个问题曾经困扰了我半个多月.MySQL使用是很具伸缩性的算法,因此你通 ...

  5. sql注入实例分析

    什么是SQL注入攻击?引用百度百科的解释: sql注入_百度百科: 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具 ...

  6. 实例分析ELF文件静态链接

    参考文献: <ELF V1.2> <程序员的自我修养---链接.装载与库>第4章 静态链接 开发平台: [thm@tanghuimin static_link]$ uname ...

  7. 用实例分析H264 RTP payload

    用实例分析H264 RTP payload H264的RTP中有三种不同的基本负载(Single NAL,Non-interleaved,Interleaved) 应用程序可以使用第一个字节来识别. ...

  8. nodejs的模块系统(实例分析exprots和module.exprots)

    前言:工欲善其事,必先利其器.模块系统是nodejs组织管理代码的利器也是调用第三方代码的途径,本文将详细讲解nodejs的模块系统.在文章最后实例分析一下exprots和module.exprots ...

  9. Android Touch事件原理加实例分析

    Android中有各种各样的事件,以响应用户的操作.这些事件可以分为按键事件和触屏事件.而Touch事件是触屏事件的基础事件,在进行Android开发时经常会用到,所以非常有必要深入理解它的原理机制. ...

随机推荐

  1. Nginx 单机百万QPS环境搭建

    一.背景 最近公司在做一些物联网产品,物物通信用的是MQTT协议,内部权限与内部关系等业务逻辑准备用HTTP实现.leader要求在本地测试中要模拟出百万用户同时在线的需求.虽然该产品最后不一定有这么 ...

  2. SNF开发平台WinForm之九-代码生成器使用说明-SNF快速开发平台3.3-Spring.Net.Framework

    下面就具体的使用说明: 1.获取代码生成器的授权码(根据本机)-----还原数据库-------改config-----代码生成器 改代码生成器Config 2.登录代码生成器 3.查看是否连接成功 ...

  3. RESTful API 设计指南【转】

    网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机.平板.桌面电脑.其他专用设备......). 因此,必须有一种统一的机制,方便不同的前端设备与后端进行通信.这导致AP ...

  4. Understanding CMS GC Logs--转载

    原文地址:https://blogs.oracle.com/poonam/entry/understanding_cms_gc_logs Understanding CMS GC Logs By Po ...

  5. 笔试测试开发题三道(python)

    笔试遇到的三道测试开发题,虽然都不难,但关键还是思路吧!我想在开发东西的时候应该具备的就是思路,有了思路尝试去写,或查相关文档或代码,在此基础上需要不断调整最终达到需求.思路又是在不断练习中获得的. ...

  6. mobile 更改hosts

    在Android下,/etc是link到/system/etc的,我们需要修改/system/etc/hosts来实现.但是这个文件是只读,不能通过shell直接修改.可以通过连接到PC上使用adb来 ...

  7. SQL 关于apply的两种形式cross apply 和 outer apply

    SQL 关于apply的两种形式cross apply 和 outer apply 例子: CREATE TABLE [dbo].[Customers]( ) COLLATE Chinese_PRC_ ...

  8. Windows及Linux平台下的计时函数总结

    本文对Windows及Linux平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的各种函数.比如Window平台下特有的Windows API函数GetTickCount().timeG ...

  9. 连接不上mysqlworkbench问题解决方法

    连接mysqlworkbench出现如下提示:     查看ip     加入host的范围 mysql> select user,host from mysql.user;+--------- ...

  10. SCRUM项目 4.0

    4.0----------------------------------------------- 1.准备看板. 形式参考图4. 2.任务认领,并把认领人标注在看板上的任务标签上. 先由个人主动领 ...