RightViewController.m 5.37 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
@property (nonatomic,strong) NSMutableArray *dataArray;
曹云霄's avatar
曹云霄 committed
21
@property (nonatomic,strong) NSArray *imageArray;
曹云霄's avatar
曹云霄 committed
22 23

@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 47 48 49 50 51 52 53 54 55 56 57 58


/**
 *  图片
 */
- (NSArray *)imageArray
{
    if (_imageArray == nil) {
        
        _imageArray = [NSArray arrayWithObjects:@"tiyan",@"changjing",@"chanping",@"kehu",@"guanyu", nil];
    }
    return _imageArray;
}



曹云霄's avatar
曹云霄 committed
59 60 61 62
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
曹云霄's avatar
曹云霄 committed
63 64 65 66 67 68 69 70 71 72 73
    [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];
曹云霄's avatar
曹云霄 committed
74
    self.rightTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
曹云霄's avatar
曹云霄 committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    [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
94 95 96 97
    if (self.isOpen && ([cell.textLabel.text isEqualToString:@"所有客户"] || [cell.textLabel.text isEqualToString:@"客户订单"])) {
        
        cell.backgroundColor = kMainBlueColor;
    }
曹云霄's avatar
曹云霄 committed
98 99 100 101 102 103
    else
    {
        cell.imageView.image = [UIImage imageNamed:[self.imageArray objectAtIndex_opple:indexPath.row]];
    }
    
    
曹云霄's avatar
曹云霄 committed
104 105 106 107 108 109 110
    return  cell;
}

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

曹云霄's avatar
曹云霄 committed
112 113
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    [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
    {
zhu's avatar
zhu committed
131 132 133 134 135 136 137 138
        if (![[self.dataArray objectAtIndex_opple:indexPath.row]isEqualToString:@"体验中心"]) {
            //收起右侧控制器
            [SHARED_APPDELEGATE.mmdrawer toggleDrawerSide:MMDrawerSideRight animated:YES completion:^(BOOL finished) {
                
                [self recoveryCell];
            }];

        }
曹云霄's avatar
曹云霄 committed
139 140 141 142 143
        
        if ([self.delegate respondsToSelector:@selector(SelectedControllerWithIndex:)]) {
            
            [self.delegate SelectedControllerWithIndex:[self.dataArray objectAtIndex_opple:indexPath.row]];
        }
zhu's avatar
zhu committed
144
    }
曹云霄's avatar
曹云霄 committed
145 146
}

曹云霄's avatar
曹云霄 committed
147 148 149 150
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
曹云霄's avatar
曹云霄 committed
151 152


曹云霄's avatar
曹云霄 committed
153 154 155 156 157 158 159 160 161 162 163 164 165
#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
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
- (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