源代码下载地址: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. js判断手机浏览器并跳转到手机网站

    function uaredirect(murl){ try { if(document.getElementById("bdmark") != null){ return; } ...

  2. 【转】github上值得关注的前端项目

    综合/资源 frontend-dev-bookmarks 一个巨大的前端开发资源清单.star:15000 front-end-collect 分享自己长期关注的前端开发相关的优秀网站.博客.以及活跃 ...

  3. Apache+tomcat+mod_jk+centos6.2负载均衡集群配置--转载

    转载地址:http://blog.163.com/chenhui_java/blog/static/17267249420128101191860/ 注: 由于长期受转载毒害,所以本人日志均是原创:其 ...

  4. TogetherJS – 酷!在网站中添加在线实时协作功能

    TogetherJS是一个免费.开源的 JavaScript 库,来自 Mozilla 实验室,可以实现基于 Web 的在线协作功能.把 TogetherJS 添加到您的网站中,您的用户可以在实时的互 ...

  5. EPANET中读取INPUT文件的函数文件——INPUT1.C/INPUT2.C/INPUT3.C

    首先介绍下这3个文件的关系:可以说INPUT1.C的函数粒度最大,它的函数getdata()就完成了整个INPUT文件数据的读入,该函数又调用了INPUT2.C中的部分函数,INPUT2.C文件中的函 ...

  6. DateTime to long

    private static DateTime BaseTime = new DateTime(1970, 1, 1); 将unixtime转换为.NET的DateTime public static ...

  7. springMVC中Dispatcher中的/和/*的区别

    1. 首先 / 这个是表示默认的路径,及表示:当没有找到可以匹配的URL就用这个URL去匹配.2. 在springmvc中可以配置多个DispatcherServlet,比如: 配置多个Dispatc ...

  8. STL --- UVA 123 Searching Quickly

    UVA - 123 Searching Quickly Problem's Link:   http://acm.hust.edu.cn/vjudge/problem/viewProblem.acti ...

  9. C#引用C++代码

    现在在Windows下的应用程序开发,VS.Net占据了绝大多数的份额.因此很多以前搞VC++开发的人都转向用更强大的VS.Net.在这种情况下,有很多开发人员就面临了如何在C#中使用C++开发好的类 ...

  10. Servelet面试题

    1. Servlet与JSP有什么区别? Servlet和JSP完成的功能是相同的,都可以接收用户的请求,可以对用户进行响应,可以调用业务方法. 不同点在于JSP是在html或者xml中嵌入了Java ...