SortMaskView.m 3 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9 10
//
//  SortMaskView.m
//  XFFurit
//
//  Created by 陈俊俊 on 15/8/1.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "SortMaskView.h"
#import "MaskCell.h"
陈俊俊's avatar
陈俊俊 committed
11
#define TableHeight 45
陈俊俊's avatar
陈俊俊 committed
12 13 14

@interface SortMaskView ()
{
n22's avatar
n22 committed
15
    NSIndexPath *_currentIndexPath;
陈俊俊's avatar
陈俊俊 committed
16
    NSString *_orderDirection;
陈俊俊's avatar
陈俊俊 committed
17 18 19 20
}
@end

@implementation SortMaskView
陈俊俊's avatar
陈俊俊 committed
21
- (instancetype)initWithFrame:(CGRect)frame withOrderDirection:(NSString *)orderDirection{
陈俊俊's avatar
陈俊俊 committed
22 23 24 25 26 27
    self = [super initWithFrame:frame];
    if (self) {
        self.tableView = [[UITableView alloc]initWithFrame:self.bounds style:(UITableViewStylePlain)];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self addSubview:self.tableView];
陈俊俊's avatar
陈俊俊 committed
28 29 30
        if (orderDirection.length >0) {
            if ([orderDirection isEqualToString:@"asc"]) {
                _currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
n22's avatar
n22 committed
31
            }else if ([orderDirection isEqualToString:@"desc"]){
陈俊俊's avatar
陈俊俊 committed
32
                _currentIndexPath = [NSIndexPath indexPathForRow:1 inSection:0];
n22's avatar
n22 committed
33 34
            }else{
                _currentIndexPath = [NSIndexPath indexPathForRow:2 inSection:0];
陈俊俊's avatar
陈俊俊 committed
35 36
            }
        }
陈俊俊's avatar
陈俊俊 committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    }
    return self;
}

#pragma mark - 协议
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"MaskID";
    MaskCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
n22's avatar
n22 committed
52
        cell = [[MaskCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID totalWidth:ScreenSize.width totalHeight:TableHeight];
陈俊俊's avatar
陈俊俊 committed
53 54 55 56 57 58 59
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (_dataArr.count > 0) {
        [cell setTitleStr:self.dataArr[indexPath.row]];
        cell.Commitbtn.hidden = YES;
    }
n22's avatar
n22 committed
60 61 62 63 64 65 66
    if (_currentIndexPath) {
        if (indexPath.row == _currentIndexPath.row) {
            cell.Commitbtn.hidden = NO;
        }else{
            cell.Commitbtn.hidden = YES;
        }
    }
陈俊俊's avatar
陈俊俊 committed
67 68 69 70
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //获取选中的cell
n22's avatar
n22 committed
71 72
    MaskCell *currentCell = (MaskCell *)[tableView cellForRowAtIndexPath:_currentIndexPath];
    currentCell.Commitbtn.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
73 74
    MaskCell *cell = (MaskCell *)[tableView cellForRowAtIndexPath:indexPath];
    cell.Commitbtn.hidden = NO;
n22's avatar
n22 committed
75
    _currentIndexPath = indexPath;
陈俊俊's avatar
陈俊俊 committed
76 77
    if (indexPath.row == 0) {
        [self.delegate getSortValueSelectRow:@"asc"];
n22's avatar
n22 committed
78
    }else if(indexPath.row == 1){
陈俊俊's avatar
陈俊俊 committed
79
        [self.delegate getSortValueSelectRow:@"desc"];
n22's avatar
n22 committed
80 81
    }else{
        [self.delegate getSortValueSelectRow:@"none"];
陈俊俊's avatar
陈俊俊 committed
82
    }
陈俊俊's avatar
陈俊俊 committed
83 84 85 86 87 88 89 90 91
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return TableHeight;
}

@end