ProductViewController.m 5.31 KB
Newer Older
n22's avatar
n22 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//
//  ProductViewController.m
//  XFFruit
//
//  Created by n22 on 15/8/21.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "ProductViewController.h"
#import "FooterCell.h"
#import "HeaderCell.h"
#import "ProductCell.h"
#define TableHeight 44

@interface ProductViewController ()<UITableViewDataSource,UITableViewDelegate,FooterCellDelegate>
{
    CGRect _tableFrame;
陈俊俊's avatar
陈俊俊 committed
18
    NSMutableArray *_selectRowArr;//记录当前选中的cell
n22's avatar
n22 committed
19 20 21 22 23 24 25 26 27
}
@end

@implementation ProductViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor  = XXFBgColor;
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
28 29 30 31 32
    [self initData];
    [self createView];
}
- (void)initData{
    _selectRowArr = [[NSMutableArray alloc]init];
陈俊俊's avatar
陈俊俊 committed
33 34 35 36 37
    if (!self.productArr) {
        self.productArr = [NSMutableArray array];
    }
    [self.productArr addObject:@"ffff"];
    [self.productArr addObject:@"fffff"];
n22's avatar
n22 committed
38
}
陈俊俊's avatar
陈俊俊 committed
39

n22's avatar
n22 committed
40 41 42 43 44 45 46 47 48 49
- (void)setViewFrame:(CGRect)viewFrame{
    _tableFrame = viewFrame;
}
- (void)createView{
    self.tableView = [[UITableView alloc]initWithFrame:_tableFrame style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    
陈俊俊's avatar
陈俊俊 committed
50
    NSArray *arr = @[@"商品",@"单价",@"包装数量"];
n22's avatar
n22 committed
51 52 53 54 55
    
    HeaderCell *headCell = [[HeaderCell alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 38) withArr:arr];
    [self.view addSubview:headCell];
    self.tableView.tableHeaderView = headCell;
    
陈俊俊's avatar
陈俊俊 committed
56 57 58 59 60 61
    if (!self.isHiddenEdit) {
        FooterCell *footCell = [[FooterCell alloc]initWithFrame:CGRectMake(0, 0, _tableFrame.size.width, 50) withTitle:@"+点击添加商品明细"];
        [self.view addSubview:footCell];
        footCell.delegate = self;
        self.tableView.tableFooterView = footCell;
    }
n22's avatar
n22 committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
}

- (void)addClick{
    [self.productArr addObject:@"dddd"];
    [self.tableView reloadData];
}

#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.productArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
陈俊俊's avatar
陈俊俊 committed
77
    static NSString *cellID = @"ProductCell";
n22's avatar
n22 committed
78 79 80 81
    ProductCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ProductCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
陈俊俊's avatar
陈俊俊 committed
82 83 84
        if (self.isHiddenEdit) {
            cell.editBtn.hidden = YES;
        }
n22's avatar
n22 committed
85
    }
陈俊俊's avatar
陈俊俊 committed
86
    if ([self isHaveIndexPath:indexPath]) {
n22's avatar
n22 committed
87 88 89 90 91 92 93 94
        cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
        CGRect Linefrmame = cell.lineLabel.frame;
        Linefrmame.origin.y = 200-1;
        cell.lineLabel.frame = Linefrmame;
        CGRect showfrmame = cell.showView.frame;
        showfrmame.size.height = 150;
        cell.showView.frame = showfrmame;
        cell.backgroundColor = XXFBgColor;
陈俊俊's avatar
陈俊俊 committed
95 96 97 98 99 100 101 102 103
    }else{
        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
        CGRect Linefrmame = cell.lineLabel.frame;
        Linefrmame.origin.y = TableHeight-1;
        cell.lineLabel.frame = Linefrmame;
        CGRect showfrmame = cell.showView.frame;
        showfrmame.size.height = 0;
        cell.showView.frame = showfrmame;
        cell.backgroundColor = [UIColor whiteColor];
n22's avatar
n22 committed
104 105 106
    }
    return cell;
}
陈俊俊's avatar
陈俊俊 committed
107 108 109 110 111 112 113 114
- (BOOL)isHaveIndexPath:(NSIndexPath *)indexPath{
    for (NSIndexPath *path in _selectRowArr) {
        if (path.row == indexPath.row) {
            return YES;
        }
    }
    return NO;
}
n22's avatar
n22 committed
115 116 117 118 119 120 121 122 123 124
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProductCell *cell = (ProductCell *)[tableView cellForRowAtIndexPath:indexPath];
    CGRect Linefrmame = cell.lineLabel.frame;
    CGRect showfrmame = cell.showView.frame;
    if (Linefrmame.origin.y == TableHeight - 1) {
        cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];

        Linefrmame.origin.y = 200-1;
        showfrmame.size.height = 150;
陈俊俊's avatar
陈俊俊 committed
125
//        cell.showView.hidden = NO;
n22's avatar
n22 committed
126
        cell.backgroundColor = [UIColor whiteColor];
陈俊俊's avatar
陈俊俊 committed
127
        [_selectRowArr addObject:indexPath];
n22's avatar
n22 committed
128 129 130 131
    }else{
        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
        Linefrmame.origin.y = TableHeight -1;
        showfrmame.size.height = 0;
陈俊俊's avatar
陈俊俊 committed
132
//        cell.showView.hidden = YES;
n22's avatar
n22 committed
133
        cell.backgroundColor = [UIColor whiteColor];
陈俊俊's avatar
陈俊俊 committed
134
        [_selectRowArr removeObject:indexPath];
n22's avatar
n22 committed
135 136 137 138 139 140 141 142
    }
    cell.lineLabel.frame = Linefrmame;
    cell.showView.frame = showfrmame;
    [self.tableView reloadData];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
陈俊俊's avatar
陈俊俊 committed
143
    if ([self isHaveIndexPath:indexPath]) {
n22's avatar
n22 committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
        return 200;
    }
    return TableHeight;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end