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 - 100, 8, kScreenWidth, 28)];
    headView.backgroundColor = [UIColor whiteColor];
    headView.layer.masksToBounds = YES;
    headView.layer.cornerRadius = 5;
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(6, 6, 16, 16)];
    image.image = [UIImage imageNamed:@"search_k"];
    [headView addSubview:image];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image.frame) + 7, 0, 150, headView.frame.size.height)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:13];
    label.text = @"搜索商品";
    [headView addSubview:label];
    
    UIButton *rightButton =  [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 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(0, 0, 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(0, 8, kScreenWidth, 28)];
    // headView.backgroundColor = [UIColor grayColor];
    headView.layer.masksToBounds = YES;
    
    
    UIView *leftHeadView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, kScreenWidth-100, 28)];
    leftHeadView.backgroundColor = [UIColor whiteColor];
    leftHeadView.layer.masksToBounds = YES;
    leftHeadView.layer.cornerRadius = 5;
    
    UIView *rightHeadView = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth-90, 0, 90, 28)];
    leftHeadView.backgroundColor = [UIColor whiteColor];
    leftHeadView.layer.masksToBounds = YES;
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(6, 6, 16, 16)];
    image.image = [UIImage imageNamed:@"search_k"];
    [leftHeadView addSubview:image];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image.frame) + 7, 0, 150, headView.frame.size.height)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:13];
    label.text = @"搜索商品";
    [leftHeadView addSubview:label];
    
    UIButton *searchButton =  [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 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(0, 0, 75, 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(0, 0, 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==0){
        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:0];
    
    
    /**
     *  构建需要数据 2层或者3层数据 (ps 2层也当作3层来处理)
     */
    NSInteger type1count=self.type1Array.count;
    for (int i=0; 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:0];
        NSInteger type2count=type1.type2Array.count;
        for ( int j=0; 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:0];
            
            NSInteger type3count=type2.type3Array.count;
            for ( int z=0; 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>0)
            {
                meun1.nextArray=zList;
            }
        }
        
        if(type2count > 0){
            meun.nextArray=sub;
        }
        
        [lis addObject:meun];
    }
    
    
    MultilevelMenu * view=[[MultilevelMenu alloc] initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight-112) 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:30];
    
    
    [connect postRequestForPostValue:dic url:@"gettype.php" requestTag:1];
}

-(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>0){
        [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: @"0"]){
        NSArray *dataArray = [request.responseObject objectForKey:@"data"];
        if(dataArray){
            for(int i=0;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=0;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=0;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即可下载工程源码


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM