MaterialVIewController.m 4.22 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 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
//
//  MaterialVIewController.m
//  XFFruit
//
//  Created by n22 on 15/8/19.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "MaterialVIewController.h"
#import "HeaderCell.h"
#import "FooterCell.h"
#import "MaterialCell.h"
#define TableHeight 44


@interface MaterialVIewController ()<UITableViewDataSource,UITableViewDelegate,FooterCellDelegate>
{
    CGRect _tableFrame;
    NSInteger _currentRow;
    BOOL isFirst;
}
@end

@implementation MaterialVIewController


- (void)viewDidLoad {
    self.view.backgroundColor  = XXFBgColor;
    [super viewDidLoad];
    isFirst = YES;
    _meterialArr = [NSMutableArray array];
    [self createView];
}
- (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.view addSubview:self.tableView];
    
    NSArray *arr = @[@"原料",@"基础数量",@"入库时间"];
    
    HeaderCell *headCell = [[HeaderCell alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 38) withArr:arr];
    [self.view addSubview:headCell];
    self.tableView.tableHeaderView = headCell;
    
    FooterCell *footCell = [[FooterCell alloc]initWithFrame:CGRectMake(0, 0, _tableFrame.size.width, 50) withTitle:@"+点击添加原料明细"];
    [self.view addSubview:footCell];
    footCell.delegate = self;
    self.tableView.tableFooterView = footCell;
}

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

#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.meterialArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"MaterialCell";
    MaterialCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MaterialCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
n22's avatar
n22 committed
72
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
n22's avatar
n22 committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    }
    if (indexPath.row != _currentRow) {
        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.showView.hidden = YES;
        cell.backgroundColor = [UIColor whiteColor];
        
    }else if (indexPath.row == _currentRow && !isFirst)
    {
        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.showView.hidden = NO;
        cell.backgroundColor = XXFBgColor;
    }

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MaterialCell *cell = (MaterialCell *)[tableView cellForRowAtIndexPath:indexPath];
    CGRect Linefrmame = cell.lineLabel.frame;
     CGRect showfrmame = cell.showView.frame;
    if (Linefrmame.origin.y == TableHeight - 1) {
        Linefrmame.origin.y = 200-1;
        showfrmame.size.height = 150;
        cell.showView.hidden = NO;
        isFirst = NO;
        cell.backgroundColor = [UIColor whiteColor];

    }else{
        isFirst = YES;
        Linefrmame.origin.y = TableHeight -1;
        showfrmame.size.height = 0;
        cell.showView.hidden = YES;
n22's avatar
n22 committed
117
        cell.backgroundColor = [UIColor whiteColor];
n22's avatar
n22 committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

    }
    cell.lineLabel.frame = Linefrmame;
    cell.showView.frame = showfrmame;
    _currentRow = indexPath.row;
    [self.tableView reloadData];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == _currentRow && !isFirst) {
        return 200;
    }
    return TableHeight;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end