iOS开发总结-类似京东分类,UICollectionView
//
// TypeViewController.m
// BJ
//
// Created by shirenfeng on 16/11/6.
// Copyright © 2016年 com.wsb123. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "CustomActivityIndicator.h"
#import "TypeViewController.h"
#import "HttpConnect.h"
#import "FTMacro.h"
#import "UIImageView+WebCache.h"
#import "Utilities.h"
#import "NoNetWorkingView.h"
#import "DBStrore.h"
#import "TagsTableCell.h"
#import "MultilevelMenu.h"
#import "TagsTableViewController.h"
#import "BrandViewController.h"
#import "PicViewController.h"
@interface TypeViewController () @property (strong, nonatomic) UIButton *mLookPicButton; @end @implementation TypeViewController - (void)viewDidLoad00 {
[super viewDidLoad]; NSLog(@"MY TYPEVIEWCONTROLLER"); UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
backItem.title = @"返回";
self.navigationItem.backBarButtonItem = backItem; UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth - , , kScreenWidth, )];
headView.backgroundColor = [UIColor whiteColor];
headView.layer.masksToBounds = YES;
headView.layer.cornerRadius = ; UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
image.image = [UIImage imageNamed:@"search_k"];
[headView addSubview:image]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image.frame) + , , , headView.frame.size.height)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor grayColor];
label.font = [UIFont systemFontOfSize:];
label.text = @"搜索商品";
[headView addSubview:label]; UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(, , headView.frame.size.width, headView.frame.size.height)];
[rightButton addTarget:self action:@selector(pushSearchView:) forControlEvents:UIControlEventTouchUpInside];
rightButton.backgroundColor = [UIColor clearColor];
[headView addSubview:rightButton]; self.navigationItem.titleView = headView; self.mTableView = [[UITableView alloc] initWithFrame:CGRectMake(, , kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
self.mTableView.backgroundColor = [UIColor whiteColor];
self.mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.mTableView.showsVerticalScrollIndicator = YES;
[self.view addSubview:self.mTableView]; self.type1Array=[[NSMutableArray alloc] init];
[self getType ]; }
- (void)viewDidLoad {
[super viewDidLoad]; NSLog(@"MY TYPEVIEWCONTROLLER"); UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
backItem.title = @"返回";
self.navigationItem.backBarButtonItem = backItem; UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(, , kScreenWidth, )];
// headView.backgroundColor = [UIColor grayColor];
headView.layer.masksToBounds = YES; UIView *leftHeadView = [[UIView alloc] initWithFrame:CGRectMake(, , kScreenWidth-, )];
leftHeadView.backgroundColor = [UIColor whiteColor];
leftHeadView.layer.masksToBounds = YES;
leftHeadView.layer.cornerRadius = ; UIView *rightHeadView = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth-, , , )];
leftHeadView.backgroundColor = [UIColor whiteColor];
leftHeadView.layer.masksToBounds = YES; UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
image.image = [UIImage imageNamed:@"search_k"];
[leftHeadView addSubview:image]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image.frame) + , , , headView.frame.size.height)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor grayColor];
label.font = [UIFont systemFontOfSize:];
label.text = @"搜索商品";
[leftHeadView addSubview:label]; UIButton *searchButton = [[UIButton alloc] initWithFrame:CGRectMake(, , leftHeadView.frame.size.width, headView.frame.size.height)];
[searchButton addTarget:self action:@selector(pushSearchView:) forControlEvents:UIControlEventTouchUpInside];
searchButton.backgroundColor = [UIColor clearColor];
[leftHeadView addSubview:searchButton]; [headView addSubview:leftHeadView]; UIButton *lookPicButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , headView.frame.size.height)];
[lookPicButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[lookPicButton setTitle:@"对比(..)" forState:UIControlStateNormal];
// [lookPicButton setTitle:@"对比(..)" forState:UIControlStateHighlighted];
[lookPicButton setTitleColor:self.view.tintColor forState:UIControlStateNormal];
lookPicButton.backgroundColor = [UIColor clearColor];
lookPicButton.titleLabel.font = [UIFont systemFontOfSize: 15.0];
[lookPicButton addTarget:self action:@selector(lookPicBtnClick) forControlEvents:UIControlEventTouchUpInside];
_mLookPicButton=lookPicButton; [rightHeadView addSubview:lookPicButton]; [headView addSubview:rightHeadView]; self.navigationItem.titleView = headView; self.mTableView = [[UITableView alloc] initWithFrame:CGRectMake(, , kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
self.mTableView.backgroundColor = [UIColor whiteColor];
self.mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.mTableView.showsVerticalScrollIndicator = YES;
[self.view addSubview:self.mTableView]; self.type1Array=[[NSMutableArray alloc] init]; NSLog(@"viewdidload get type");
//[self getType ]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(freshCapPicCount:) name:@"freshCapPicCount" object:nil]; }
- (void)lookPicBtnClick
{
PicViewController *picVC = (PicViewController *)[[UIStoryboard storyboardWithName:@"picview" bundle:nil] instantiateViewControllerWithIdentifier:@"PicViewController"]; [self.navigationController pushViewController:picVC animated:YES]; }
-(void)viewWillAppear:(BOOL)animated
{
//开启定时器
// [scrollView.myTimer setFireDate:[NSDate distantPast]];
NSLog(@"viewWillAppear:%d",[DBStrore sharedDBStore].CapPicArray.count);
[_mLookPicButton setTitle:[NSString stringWithFormat:@"对比(%d)",[DBStrore sharedDBStore].CapPicArray.count] forState: UIControlStateNormal]; if(self.type1Array.count==){
NSLog(@"viewWillAppear get type");
[self getType ];
}
}
-(void) freshCapPicCount:(NSNotification*)notify
{
NSLog(@"type brand view freshCapPicCount:%d",[DBStrore sharedDBStore].CapPicArray.count);
[_mLookPicButton setTitle:[NSString stringWithFormat:@"对比(%d)",[DBStrore sharedDBStore].CapPicArray.count] forState: UIControlStateNormal];
}
-(void)viewDidDisappear:(BOOL)animated
{
//关闭定时器
//[scrollView.myTimer setFireDate:[NSDate distantFuture]];
NSLog(@"viewDidDisappear");
} - (void)timeOut:(id)time
{
[Utilities removeMyGifImageView:self.view];
} /*
-(void)setupMenu000
{
NSMutableArray * lis=[NSMutableArray arrayWithCapacity:0]; * 构建需要数据 2层或者3层数据 (ps 2层也当作3层来处理) NSInteger countMax=20;
for (int i=0; i<countMax; i++) { rightMeun * meun=[[rightMeun alloc] init];
meun.meunName=[NSString stringWithFormat:@"菜单%d",i];
NSMutableArray * sub=[NSMutableArray arrayWithCapacity:0];
for ( int j=0; j <countMax+1; j++) { rightMeun * meun1=[[rightMeun alloc] init];
meun1.meunName=[NSString stringWithFormat:@"菜单%d的头菜单%d",i,j]; [sub addObject:meun1]; //meun.meunNumber=2; NSMutableArray *zList=[NSMutableArray arrayWithCapacity:0];
// if (j%2==0)
{ for ( int z=0; z <countMax+2; z++) { rightMeun * meun2=[[rightMeun alloc] init];
meun2.ID=[NSString stringWithFormat:@"id:%d-%d-%d",i,j,z];
meun2.urlName=@"http://img10.360buyimg.com/n7/jfs/t2182/214/885877100/114709/65627d58/563041eeNa301882b.jpg";
meun2.meunName=[NSString stringWithFormat:@"菜单%d的头菜单%d的第%d个",i,j,z]; [zList addObject:meun2]; }
} meun1.nextArray=zList;
} meun.nextArray=sub;
[lis addObject:meun];
} MultilevelMenu * view=[[MultilevelMenu alloc] initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight-114) WithData:lis withSelectIndex:^(NSInteger left, NSInteger right,rightMeun* info) { NSLog(@"点击的 left=%d right=%d ID=%@",left,right,info.ID); BrandViewController *brandView = [[BrandViewController alloc] initWithNibName:@"BrandViewController" bundle:nil];
brandView.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:brandView animated:YES]; // [[DBStrore sharedDBStore] showInformationView:7]; }]; // view.leftSelectColor=[UIColor greenColor];
// view.leftSelectBgColor=[UIColor redColor];
view.isRecordLastScroll=YES;
[self.view addSubview:view]; }
*/ -(void)setupMenu
{
NSMutableArray * lis=[NSMutableArray arrayWithCapacity:]; /**
* 构建需要数据 2层或者3层数据 (ps 2层也当作3层来处理)
*/
NSInteger type1count=self.type1Array.count;
for (int i=; i<type1count; i++) {
type1Model *type1=[self.type1Array objectAtIndex:i];
rightMeun * meun=[[rightMeun alloc] init];
// meun.meunName=[NSString stringWithFormat:@"菜单%d %@",i,type1.name];
meun.meunName=[NSString stringWithFormat:@"%@",type1.name];
// NSLog(@"type1name:%@",meun.meunName);
NSMutableArray * sub=[NSMutableArray arrayWithCapacity:];
NSInteger type2count=type1.type2Array.count;
for ( int j=; j <type2count; j++) {
type2Model *type2=[type1.type2Array objectAtIndex:j];
rightMeun * meun1=[[rightMeun alloc] init];
// meun1.meunName=[NSString stringWithFormat:@"菜单%d的头菜单%d %@",i,j,type2.name];
meun1.meunName=[NSString stringWithFormat:@"%@",type2.name];
// NSLog(@"type2name:%@",meun1.meunName);
[sub addObject:meun1]; //meun.meunNumber=2; NSMutableArray *zList=[NSMutableArray arrayWithCapacity:]; NSInteger type3count=type2.type3Array.count;
for ( int z=; z <type3count; z++) {
type3Model *type3=[type2.type3Array objectAtIndex:z];
rightMeun * meun2=[[rightMeun alloc] init];
// meun2.ID=[NSString stringWithFormat:@"id:%d-%d-%d=%d",i,j,z,type3.type3id];
meun2.ID=[NSString stringWithFormat:@"%d",type3.type3id];
meun2.urlName=type3.pic;
// @"http://img10.360buyimg.com/n7/jfs/t2182/214/885877100/114709/65627d58/563041eeNa301882b.jpg";
// meun2.meunName=[NSString stringWithFormat:@"菜单%d的头菜单%d的第%d个",i,j,z];
meun2.meunName=[NSString stringWithFormat:@"%@",type3.name];
// NSLog(@"type3name:%@",meun2.meunName); [zList addObject:meun2]; } if(type3count>)
{
meun1.nextArray=zList;
}
} if(type2count > ){
meun.nextArray=sub;
} [lis addObject:meun];
} MultilevelMenu * view=[[MultilevelMenu alloc] initWithFrame:CGRectMake(, , kScreenWidth, kScreenHeight-) WithData:lis withSelectIndex:^(NSInteger left, NSInteger right,rightMeun* info) { NSLog(@"点击的 left=%d right=%d ID=%@",left,right,info.ID); BrandViewController *brandView = [[BrandViewController alloc] initWithNibName:@"BrandViewController" bundle:nil];
brandView.type3id=[info.ID intValue];
brandView.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:brandView animated:YES]; // [[DBStrore sharedDBStore] showInformationView:7]; }]; // view.leftSelectColor=[UIColor greenColor];
// view.leftSelectBgColor=[UIColor redColor];
view.isRecordLastScroll=YES;
[self.view addSubview:view]; } -(void)getType
{
HttpConnect * connect = [[HttpConnect alloc] init];
connect.delegate = self;
NSMutableDictionary * dic = [NSMutableDictionary dictionary]; [Utilities addMyGifImageView:self];
[self performSelector:@selector(timeOut:) withObject:self afterDelay:]; [connect postRequestForPostValue:dic url:@"gettype.php" requestTag:];
} -(void)postRequestStarted:(AFHTTPRequestOperation*)request manage:(AFHTTPRequestOperationManager*)manage{ NSLog(@"REQ START");
}
-(void)postRequestFinished:(AFHTTPRequestOperation*)request manage:(AFHTTPRequestOperationManager*)manage{ NSLog(@"REQ FINISHED");
[Utilities removeMyGifImageView:self.view];
if(self.type1Array.count>){
[self.type1Array removeAllObjects];
} NSDictionary * dictionary = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableLeaves error:nil ];
NSString * status = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"status"]];
// NSLog(@"status=%@",status);
if([status isEqualToString: @""]){
NSArray *dataArray = [request.responseObject objectForKey:@"data"];
if(dataArray){
for(int i=;i<dataArray.count;i++){
type1Model *type1=[[type1Model alloc] init];
type1.type1id=[[dataArray[i] objectForKey:@"type1id"] intValue];
type1.type=[[dataArray[i] objectForKey:@"type"] intValue];
type1.name=[dataArray[i] objectForKey:@"name"]; NSArray *type2Array = [dataArray[i] objectForKey:@"type2table"];
if(type2Array){
for(int i=;i<type2Array.count;i++){
type2Model *type2=[[type2Model alloc] init];
type2.type2id=[[type2Array[i] objectForKey:@"type2id"] intValue];
type2.name=[type2Array[i] objectForKey:@"name"]; NSArray *type3Array = [type2Array[i] objectForKey:@"type3table"];
if(type3Array){
for(int i=;i<type3Array.count;i++){
type3Model *type3=[[type3Model alloc] init];
type3.type3id=[[type3Array[i] objectForKey:@"type3id"] intValue];
type3.name=[type3Array[i] objectForKey:@"name"];
type3.pic=[type3Array[i] objectForKey:@"pic"];
NSLog(@"type3.pic=%@",type3.pic);
type3.topprice=[[type3Array[i] objectForKey:@"topprice"] intValue];
type3.url=[type3Array[i] objectForKey:@"url"];
[type2.type3Array addObject:type3];
}
}
[type1.type2Array addObject:type2];
}
}
[self.type1Array addObject:type1];
}
[self setupMenu];
} } }
-(void)postRequestFailed:(AFHTTPRequestOperation*)request manage:(AFHTTPRequestOperationManager*)manage{ [Utilities removeMyGifImageView:self.view];
NSLog(@"REQ FAILED");
// [self.view addSubview:[CustomAlertView alertWith:@"0" message:NSLocalizedString(@"error", @"错误")]];
} - (void)pushSearchView:(id)sender
{
TagsTableViewController *tagVC = (TagsTableViewController *)[[UIStoryboard storyboardWithName:@"Search" bundle:nil] instantiateViewControllerWithIdentifier:@"TagsTableViewController"];
//tagVC.is_pushGuideInfoView = NO;
//tagVC.type = 1;
[self.navigationController pushViewController:tagVC animated:YES]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
加扣群385378208即可下载工程源码
iOS开发总结-类似京东分类,UICollectionView的更多相关文章
- iOS开发——UI篇OC篇&UICollectionView详解+实例
UICollectionView详解+实例 实现步骤: 一.新建两个类 1.继承自UIScrollView的子类,比如HMWaterflowView * 瀑布流显示控件,用来显示所有的瀑布流数据 2. ...
- iOS开发中常用的分类方法---UIImage+Category
在开发中使用分类对原有的系统类进行方法扩展,是增强系统原有类功能的常见做法. /** * 自由拉伸一张图片 * * @param name 图片名字 * @param left 左边开始位置比例 值范 ...
- iOS开发学习-类似微信聊天消息中的电话号码点击保存到通讯录中的功能
类似微信聊天消息中的电话号码点击保存到通讯录中的功能,ABAddress的实现在iOS9中是不能正常使用的,点击完成后,手机会非常的卡,iOS9之后需要使用Contact新提供的方法来实现该功能.快捷 ...
- IOS开发之——类似微信摇一摇的功能实现
首先,一直以为摇一摇的功能实现好高大上,结果百度了.我自己也模仿写了一个demo.主要代码如下: 新建一个项目,名字为AnimationShake. 主要代码: - (void)motionBegan ...
- iOS开发之圆角指定 分类: ios技术 2015-05-25 16:26 191人阅读 评论(0) 收藏
如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某几个角(小于4)为圆角而别的不变时 ...
- iOS 开发中类似上下滚动弹幕实现原理
#mark ---滚动弹幕 列表中留有7条记录 大于7条时删除并指引表视图向上滑动 - (void)addRowActionWithContent:(NSString *)str { if (sel ...
- iOS开发——OC篇&OC高级语法
iOS开发高级语法之分类,拓展,协议,代码块详解 一:分类 什么是分类Category? 分类就是类的补充和扩展部分 补充和扩展的每个部分就是分类 分类本质上是类的一部分 分类的定义 分类也是以代码的 ...
- iOS开发之主题皮肤
iOS开发之主题皮肤 分类: [iOS] 最近在开发一款[公交应用],里面有个模块涉及到主题设置,这篇文章主要谈一下个人的做法. 大概的步骤如下: (1):整个应用依赖于一个主题管理器,主题管理器根 ...
- iOS仿京东分类菜单之UICollectionView内容
在上<iOS仿京东分类菜单实例实现>已经实现了大部分主体的功能,本文是针对右边集合列表进行修改扩展,使它达到分组的效果,本文涉及到的主要是UICollectionView的知识内容,左边列 ...
随机推荐
- jquery text--val--html
.html()用为读取和修改元素的HTML标签 对应js中的innerHTML .html()是用来读取元素的HTML内容(包括其Html标签),.html()方法使用在多个元素上时,只读取第一 ...
- 使用APPLICATION制作缓存,转存一下,有一段写的还可以。
public sealed class CacheManager { private HttpApplicationState appPool = null; /// <summar ...
- HMM模型
通过前几时断续的学习,发现自己对HMM模型的了解还只停留在皮毛,导致在学习CRF模型并将其与最大熵模型.HMM.MEMM做比较时感觉很吃力,所以又花了两天时间使劲看了遍HMM,发现了解得确实深刻了很多 ...
- 使用OPCDAAuto.dll编写C# OPC采集程序
在一台新机器上运行使用OPC自动化接口编写的C#程序报错如下: 索 COM 类工厂中 CLSID 为 {28E68F9A-8D75-11D1-8DC3-3C302A000000} 的组件失败,原因是出 ...
- document.body.clientWidth vs document.documentElement.clientWidth
http://blog.csdn.net/zb0567/article/details/7182391 mobile web javascript library http://www.gbin1.c ...
- Vim识别编码
http://blog.chinaunix.net/uid-20357359-id-1963123.html
- Android 使用HttpClient方式提交GET请求
public void httpClientGet(View view) { final String username = usernameEditText.getText().toString() ...
- jsp的url后跟中文参数传参出现乱码
①重新编码:String urlParam= request.getParameter("urlParam"); urlParam= new String(urlParam.ge ...
- 两次fopen不同的文件返回相同的FILE* 地址
最近接触一个垃圾程序,出现一个奇怪的bug,现象是两次fopen不同的文件返回相同的FILE*地址,第二次返回的FILE*有时候无端端的就被关闭了.以下代码是对这个bug的概括: auto fp1 = ...
- Linux Shell编程(20)——基本命令
新手必须要掌握的初级命令ls基本的列出所有文件的命令.但是往往就是因为这个命令太简单,所以我们总是低估它.比如,用 -R 选项,这是递归选项,ls 将会以目录树的形式列出所有文件, 另一个很有用的选项 ...