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

#import "RightViewController.h"
曹云霄's avatar
曹云霄 committed
10
#import "AppDelegate.h"
11 12 13 14 15 16






曹云霄's avatar
曹云霄 committed
17 18 19
@interface RightViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *rightTableview;
曹云霄's avatar
曹云霄 committed
20 21 22 23
@property (nonatomic,strong) NSMutableArray *dataArray;


@property (nonatomic,assign) BOOL isOpen;
曹云霄's avatar
曹云霄 committed
24 25 26 27 28

@end

@implementation RightViewController

曹云霄's avatar
曹云霄 committed
29 30 31 32 33 34 35 36 37
/**
 *  初始化数据源
 *
 *  @return NSArray
 */
- (NSArray *)dataArray
{
    if (_dataArray == nil) {
        
曹云霄's avatar
曹云霄 committed
38
        _dataArray = [NSMutableArray arrayWithObjects:@"体验中心",@"场景库",@"产品库",@"客户管理",@"关于", nil];
曹云霄's avatar
曹云霄 committed
39 40 41 42
    }
    return _dataArray;
}

曹云霄's avatar
曹云霄 committed
43 44 45 46
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
曹云霄's avatar
曹云霄 committed
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 72 73 74 75 76
    [self uiConfigAction];
}

#pragma mark -布局
- (void)uiConfigAction
{
    self.rightTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, RightWidth, ScreenHeight) style:UITableViewStylePlain];
    self.rightTableview.delegate = self;
    self.rightTableview.dataSource = self;
    [self.view addSubview:self.rightTableview];
    self.rightTableview.tableFooterView = [UIView new];
    [self.rightTableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"rightcell"];
    [self createHeaderview];
}

#pragma mark -头部视图
- (void)createHeaderview
{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, RightWidth, 200)];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
    imageView.center = CGPointMake(RightWidth/2, 100);
    imageView.image = TCImage(@"weibo");
    [headerView addSubview:imageView];
    self.rightTableview.tableHeaderView = headerView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"rightcell" forIndexPath:indexPath];
    cell.textLabel.text = [self.dataArray objectAtIndex_opple:indexPath.row];
曹云霄's avatar
曹云霄 committed
77 78 79 80
    if (self.isOpen && ([cell.textLabel.text isEqualToString:@"所有客户"] || [cell.textLabel.text isEqualToString:@"客户订单"])) {
        
        cell.backgroundColor = kMainBlueColor;
    }
曹云霄's avatar
曹云霄 committed
81 82 83 84 85 86 87
    return  cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
曹云霄's avatar
曹云霄 committed
88

曹云霄's avatar
曹云霄 committed
89 90
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
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 117
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if ([cell.textLabel.text isEqualToString:@"客户管理"] ) {
        
        if (!self.isOpen) {
            
            self.isOpen = YES;
            [self.dataArray insertObject:@"所有客户" atIndex:self.dataArray.count-1];
            [self.dataArray insertObject:@"客户订单" atIndex:self.dataArray.count-1];
            [self.rightTableview insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:4 inSection:0],[NSIndexPath indexPathForRow:5 inSection:0]] withRowAnimation:UITableViewRowAnimationMiddle];
        }
        else
        {
            [self recoveryCell];
        }
    }else
    {
        //收起右侧控制器
        [SHARED_APPDELEGATE.mmdrawer toggleDrawerSide:MMDrawerSideRight animated:YES completion:^(BOOL finished) {
            
            [self recoveryCell];
        }];
        
        if ([self.delegate respondsToSelector:@selector(SelectedControllerWithIndex:)]) {
            
            [self.delegate SelectedControllerWithIndex:[self.dataArray objectAtIndex_opple:indexPath.row]];
        }
zhu's avatar
zhu committed
118
    }
曹云霄's avatar
曹云霄 committed
119 120
}

曹云霄's avatar
曹云霄 committed
121 122


曹云霄's avatar
曹云霄 committed
123 124 125 126 127 128 129 130 131 132 133 134 135
#pragma mark -复原cell
- (void)recoveryCell
{
    if ([self.dataArray containsObject:@"所有客户"] && [self.dataArray containsObject:@"客户订单"]) {
        
        self.isOpen = NO;
        [self.dataArray removeObject:@"所有客户"];
        [self.dataArray removeObject:@"客户订单"];
        [self.rightTableview deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:4 inSection:0],[NSIndexPath indexPathForRow:5 inSection:0]] withRowAnimation:UITableViewRowAnimationMiddle];
    }
}


曹云霄's avatar
曹云霄 committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
- (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