GXFFunctionsViewController.m 6.85 KB
Newer Older
freecui's avatar
freecui committed
1 2 3 4 5 6 7 8
//
//  GXFFunctionsViewController.m
//  XFFruit
//
//  Created by freecui on 15/8/27.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

freecui's avatar
freecui committed
9

freecui's avatar
freecui committed
10 11 12
#import "GXFFunctionsViewController.h"
#import "GXFDisplayFunction.h"
#import "GXFFunction.h"
freecui's avatar
freecui committed
13 14
#import "GXFFunctionDBHelper.h"
#import "GXFFunctionDB.h"
freecui's avatar
freecui committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
@interface GXFFunctionsViewController ()<UITableViewDataSource,UITableViewDelegate>

//@property (nonatomic, strong) NSArray *
@property (nonatomic, strong) UITableView *f_tableView;
@property (nonatomic, strong) NSArray *firstSectionArr;
@property (nonatomic, strong) NSArray *secondSectionArr;

@end

@implementation GXFFunctionsViewController
static NSString *cellID = @"cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initData];
    [self setupSubViews];
}
- (void)initData {
freecui's avatar
freecui committed
34 35 36 37 38 39 40
    NSUserDefaults *f_default = [NSUserDefaults standardUserDefaults];
    BOOL noDefault = [[f_default objectForKey:@"noDefault"] integerValue] > 0 ? YES : NO;
    if (!noDefault) {
        self.secondSectionArr = [[GXFFunctionDB sharedInstance]defaultdisplayFunctions];
    } else {
            self.secondSectionArr = [[GXFFunctionDB sharedInstance]originDisplayFunctions];
    }
freecui's avatar
freecui committed
41 42 43
    NSDictionary *dictOne = @{@"Id":@(1),@"functionName":@"新建行情反馈",@"imgName":@"RefreshBtn",@"isSelected":@(0)};
        NSDictionary *dictTwo = @{@"Id":@(2),@"functionName":@"查询行情反馈",@"imgName":@"RefreshBtn",@"isSelected":@(1)};
    GXFDisplayFunction *dFuntionOne = [[GXFDisplayFunction alloc]initWithDictionary:dictOne];
freecui's avatar
freecui committed
44
    GXFDisplayFunction *dFuntionTwo =[[GXFDisplayFunction alloc]initWithDictionary:dictTwo];
freecui's avatar
freecui committed
45
    self.firstSectionArr = @[dFuntionOne,dFuntionTwo];
freecui's avatar
freecui committed
46
//@[dFuntionOne,dFuntionTwo];
freecui's avatar
freecui committed
47 48 49 50 51 52 53 54 55 56
}
- (void)setupSubViews {
    [self setupRightBarBtn];
    [self setupTableView];
}
- (void)setupRightBarBtn {
    UIBarButtonItem *rightBarBtn =  [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(selectedFunctions)];
    self.navigationItem.rightBarButtonItem = rightBarBtn;
}
- (void)setupTableView {
freecui's avatar
freecui committed
57
    self.f_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - 64) style:UITableViewStyleGrouped];
freecui's avatar
freecui committed
58 59 60 61
    self.f_tableView.dataSource = self;
    self.f_tableView.delegate = self;
    //[self.f_tableView dequeueReusableCellWithIdentifier ]
    [self.view addSubview:_f_tableView];
freecui's avatar
freecui committed
62
    [_f_tableView reloadData];
freecui's avatar
freecui committed
63 64 65 66 67 68
}



#pragma BarButton Action
- (void)selectedFunctions {
freecui's avatar
freecui committed
69 70 71 72 73 74 75 76
    [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_changeIsSelectedFunctions object:nil];

    //配置功能 不是默认配置
    NSUserDefaults *f_default = [NSUserDefaults standardUserDefaults];
    BOOL noDefault = [[f_default objectForKey:@"noDefault"] integerValue] > 0 ? YES : NO;
    if (!noDefault) {
        [f_default setObject:@(1) forKey:@"noDefault"];
    }
freecui's avatar
freecui committed
77 78
    
    [self PopViewControllerAnimated:YES];
freecui's avatar
freecui committed
79 80
    
    
freecui's avatar
freecui committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
}


#pragma UITablewViewDataSource 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return _firstSectionArr.count;
    } else {
        return _secondSectionArr.count;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
freecui's avatar
freecui committed
98
    //TableViewCell重用机制避免重复显示问题  它的子视图全部删除
freecui's avatar
freecui committed
99 100 101
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
freecui's avatar
freecui committed
102 103 104
    } else {
        while ([cell.contentView.subviews lastObject] != nil) {
            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
freecui's avatar
freecui committed
105 106 107
        }
    }
    
freecui's avatar
freecui committed
108
    [self p_contentToTableViewCell:cell ForRowAtIndexPath:indexPath];
freecui's avatar
freecui committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *sectionTitle = [NSString string];
    switch (indexPath.section) {
        case 0:
        {
            sectionTitle = @"提示选择";
        }
            break;
        case 1:
        {
            sectionTitle = @"功能选择";
        }
            break;
    }
    
    return sectionTitle;
}
#pragma UITableViewDelegate 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
freecui's avatar
freecui committed
133
        switch (indexPath.section) {
freecui's avatar
freecui committed
134 135 136 137 138 139 140
        case 0:
        {
            
        }
            break;
        case 1:
        {
freecui's avatar
freecui committed
141 142 143 144 145 146 147 148 149 150 151 152
            GXFDisplayFunction *displayFunction = (GXFDisplayFunction *)_secondSectionArr[indexPath.row];
            UITableViewCell *cell = [_f_tableView  cellForRowAtIndexPath:indexPath];
            if (cell.accessoryType == UITableViewCellAccessoryNone) {
                cell.accessoryType = UITableViewCellAccessoryCheckmark;
                displayFunction.isSelected = YES;

            } else {
                cell.accessoryType = UITableViewCellAccessoryNone;
                 displayFunction.isSelected = NO;
            }
            
            [[GXFFunctionDB sharedInstance] updateDisplayFunctionIsSelectedWithId:displayFunction];
freecui's avatar
freecui committed
153 154 155 156 157 158 159 160
            
        }
            break;
    }

}

#pragma 给cell的内容赋值
freecui's avatar
freecui committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
- (void)p_contentToTableViewCell: (UITableViewCell *)cell ForRowAtIndexPath:(NSIndexPath *)indexPath  {
    switch (indexPath.section) {
        case 0:
        {
            GXFDisplayFunction *dFunction = (GXFDisplayFunction *)_firstSectionArr[indexPath.row];
            cell.imageView.image = [UIImage imageNamed:@"RefreshBtn"];//dFunction.functionImgName];
            cell.textLabel.text = dFunction.functionName;

            
        }
            break;
        case 1:
        {
            GXFDisplayFunction *dFunction = (GXFDisplayFunction *)_secondSectionArr[indexPath.row];
            cell.imageView.image = [UIImage imageNamed:@"RefreshBtn"];//dFunction.functionImgName];
            cell.textLabel.text = dFunction.functionName;
            if (dFunction.isSelected) {
                cell.accessoryType =  UITableViewCellAccessoryCheckmark;
            } else {
                cell.accessoryType = UITableViewCellAccessoryNone;
            }
        }
            break;
        default:
            break;
freecui's avatar
freecui committed
186
    }
freecui's avatar
freecui committed
187 188


freecui's avatar
freecui committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
}
- (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