screeningFirstView.m 4.05 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9
//
//  screeningFirstView.m
//  Lighting
//
//  Created by 曹云霄 on 16/5/8.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "screeningFirstView.h"
10

曹云霄's avatar
曹云霄 committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#define WIDTH self.frame.size.width

@implementation screeningFirstView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/



- (void)awakeFromNib
{
曹云霄's avatar
曹云霄 committed
27
    [super awakeFromNib];
曹云霄's avatar
曹云霄 committed
28 29 30
    [self uiConfigAction];
}

曹云霄's avatar
曹云霄 committed
31 32 33 34 35 36 37 38
#pragma mark -更新
- (void)setDatasArray:(NSArray *)datasArray
{
    _datasArray = datasArray;
    [self.classificationCollectionView reloadData];
}


曹云霄's avatar
曹云霄 committed
39 40 41 42 43 44 45 46 47
#pragma mark -UI
- (void)uiConfigAction
{
    
    self.classificationLayout.itemSize = CGSizeMake((WIDTH-120)/4, 35);
    self.classificationLayout.minimumLineSpacing = 30;
    self.classificationLayout.minimumInteritemSpacing = 10;
    self.classificationLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
    [self.classificationCollectionView registerClass:[ScreeningFirstCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
曹云霄's avatar
曹云霄 committed
48 49
    //section
    [self.classificationCollectionView registerClass:[ScreeningCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Sectioncell"];
曹云霄's avatar
曹云霄 committed
50 51
    self.classificationCollectionView.dataSource = self;
    self.classificationCollectionView.delegate = self;
曹云霄's avatar
曹云霄 committed
52
    self.classificationCollectionView.alwaysBounceVertical = YES;
曹云霄's avatar
曹云霄 committed
53
    
曹云霄's avatar
曹云霄 committed
54
    
曹云霄's avatar
曹云霄 committed
55 56 57 58 59 60
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ScreeningFirstCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
61 62
    cell.indexpath = indexPath;
    cell.delegate = self;
63 64
    if (self.selectedIndex == 1) {
        
65
        [cell.titleLabe setTitle:[[[[self.datasArray objectAtIndex_opple:indexPath.section] children] objectAtIndex_opple:indexPath.row] name] forState:UIControlStateNormal];
66 67 68
    }
    else
    {
69
        [cell.titleLabe setTitle:[[self.datasArray objectAtIndex_opple:indexPath.row] typeName] forState:UIControlStateNormal];
70 71
    }
    return cell;
曹云霄's avatar
曹云霄 committed
72 73
}

74

曹云霄's avatar
曹云霄 committed
75 76
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
曹云霄's avatar
曹云霄 committed
77 78
    if (self.selectedIndex == 1) {
        
79
        return [[[self.datasArray objectAtIndex_opple:section] children] count];
曹云霄's avatar
曹云霄 committed
80
        
曹云霄's avatar
曹云霄 committed
81 82
    }
    return self.datasArray.count;
曹云霄's avatar
曹云霄 committed
83 84
}

85 86 87

#pragma mark -选中代理
- (void)SelectedButtonClickAction:(NSIndexPath *)indexpath
曹云霄's avatar
曹云霄 committed
88
{
89
    if ([self.delegate respondsToSelector:@selector(selectedItem:withTitle:)]) {
90 91 92
        
        if (self.selectedIndex == 1 ) {
            
93
            [self.delegate selectedItem:[[[self.datasArray objectAtIndex_opple:indexpath.section] children][indexpath.row] fid] withTitle:nil];
94 95 96
            
        }else
        {
97
            [self.delegate selectedItem:[[self.datasArray objectAtIndex_opple:indexpath.row] typecode] withTitle:[[self.datasArray objectAtIndex_opple:indexpath.row] typeName]];
98 99 100
        }
        
    }
曹云霄's avatar
曹云霄 committed
101 102
}

103

曹云霄's avatar
曹云霄 committed
104 105 106 107 108 109 110 111 112 113
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    if (self.selectedIndex == 1) {
        
      return  self.datasArray.count;
    }
    return 1;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
曹云霄's avatar
曹云霄 committed
114 115 116
    
    if (self.selectedIndex == 1) {
        
117
       return CGSizeMake(200, 75);
曹云霄's avatar
曹云霄 committed
118
    }
曹云霄's avatar
曹云霄 committed
119
    return CGSizeMake(0, 0);
曹云霄's avatar
曹云霄 committed
120 121 122 123 124 125
}


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    
曹云霄's avatar
曹云霄 committed
126
    ScreeningCollectionReusableView *sectionView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Sectioncell" forIndexPath:indexPath];
127
    sectionView.sectionLabe.text = [[self.datasArray objectAtIndex_opple:indexPath.section] name];
曹云霄's avatar
曹云霄 committed
128
    return sectionView;
曹云霄's avatar
曹云霄 committed
129 130 131 132
}



曹云霄's avatar
曹云霄 committed
133 134 135 136



@end