IVTMySettingViewController.m
9.9 KB
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
72
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//
// IVTMySettingViewController.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/23.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTMySettingViewController.h"
#import "IVTEditUserInfoViewController.h"
#import "BindingTelAndThirdpartyViewController.h"
#import "IVTMyBlackListViewController.h"
#import "IVTNewMessageRemindViewController.h"
#import "IVTMyFeedBackViewController.h"
#import "AboutUsViewController.h"
#import "AppDelegate.h"
@interface IVTMySettingViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSArray *titlesArray;
UILabel *miJiaNumberLabel;
UILabel *cacheLabel;
UIButton *copyButton;
}
@end
@implementation IVTMySettingViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setNavigationBar];
titlesArray = @[@[@"蜜家号",@"编辑资料",@"账号和安全"],@[@"黑名单",@"新消息提醒",@"清理缓存"],@[@"意见反馈",@"关于我们"],@[@"退出登录"]];
__weak __typeof(self)weakSelf = self;
UITableView *myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 64) style:UITableViewStyleGrouped];
myTableView.separatorColor = UIColorFromRGBAlphaHex(0xdcdcdc, 1.0);
myTableView.dataSource = self;
myTableView.delegate = self;
myTableView.sectionFooterHeight = 1.0f;
[self.view addSubview:myTableView];
[myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.view.mas_left);
make.top.equalTo(weakSelf.view.mas_top);
make.right.equalTo(weakSelf.view.mas_right);
make.bottom.equalTo(weakSelf.view.mas_bottom);
}];
}
- (void)setNavigationBar{
self.navigationItem.title = @"设置";
}
#pragma mark - UITableViewDelegate / UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return titlesArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[titlesArray objectAtIndex:section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 46;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 21.0f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.backgroundColor =[UIColor whiteColor];
cell.textLabel.font = [UIFont IVTH3Font];
cell.textLabel.textColor = [UIColor IVTMainTextColor];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"我的更多键"]];
}
cell.textLabel.text = titlesArray[indexPath.section][indexPath.row];
if (indexPath.section == 0 && indexPath.row ==0) {
cell.accessoryView.hidden = YES;
miJiaNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth-195, 0, 135, 46)];
miJiaNumberLabel.text =[IVTAccountTool getUserId];
miJiaNumberLabel.textColor = UIColorFromRGBAlphaHex(0x5A5A5A, 1.0);
miJiaNumberLabel.font = [UIFont IVTH3Font];
miJiaNumberLabel.textAlignment = NSTextAlignmentRight;
[cell.contentView addSubview:miJiaNumberLabel];
copyButton = [UIButton buttonWithType:UIButtonTypeCustom];
copyButton.frame = CGRectMake(kScreenWidth-52, 13, 38, 19);
copyButton.layer.cornerRadius = 5.0f;
[copyButton setTitle:@"复制" forState:UIControlStateNormal];
copyButton.titleLabel.font = [UIFont YXFontOfSize:10];
[copyButton setBackgroundImage:[UIImage imageNamed:@"设置--复制按钮"] forState:UIControlStateNormal];
[copyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[copyButton addTarget:self action:@selector(copyNum:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:copyButton];
}else if (indexPath.section ==1&&indexPath.row==2){
NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
cell.accessoryView.hidden = YES;
cacheLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth-70, 0, 50, 46)];
cacheLabel.text = [NSString stringWithFormat:@"%luMB",(unsigned long)[files count]];
cacheLabel.textColor = [UIColor YXColorWithHexCode:@"#5A5A5A"];
cacheLabel.font = [UIFont YXFontOfSize:10];
cacheLabel.textAlignment = NSTextAlignmentRight;
[cell.contentView addSubview:cacheLabel];
}else if(indexPath.section == 3 && indexPath.row == 0){
cell.accessoryView = nil;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
if (indexPath.row==0) {
//Me+号
}else if (indexPath.row==1){
//编辑资料
IVTEditUserInfoViewController *editData = [[IVTEditUserInfoViewController alloc]init];
[self.navigationController pushViewController:editData animated:YES];
}else if (indexPath.row==2){
//账号和安全
BindingTelAndThirdpartyViewController *unBindingTelVC = [[BindingTelAndThirdpartyViewController alloc] init];
[self.navigationController pushViewController:unBindingTelVC animated:YES];
}
}
if (indexPath.section==1) {
if (indexPath.row==0) {//黑名单
IVTMyBlackListViewController *blackList = [[IVTMyBlackListViewController alloc]init];
[self.navigationController pushViewController:blackList animated:YES];
}else if(indexPath.row ==1){//新消息提醒
IVTNewMessageRemindViewController *newMessageRemindVC = [[IVTNewMessageRemindViewController alloc] init];
[self.navigationController pushViewController:newMessageRemindVC animated:YES];
}else if (indexPath.row ==2){//清理缓存
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否清理缓存" message:@"点击确认清理缓存" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
for (NSString *p in files) {
NSError *error;
NSString *path = [cachPath stringByAppendingPathComponent:p];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
}
}
});
[self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nil waitUntilDone:YES];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alert animated:YES completion:^{
}];
}
}
if (indexPath.section==2) {
if (indexPath.row==0) {//意见反馈
IVTMyFeedBackViewController *feedBack = [[IVTMyFeedBackViewController alloc]init];
[self.navigationController pushViewController:feedBack animated:YES];
}else if (indexPath.row==1){//关于我们
AboutUsViewController *aboutUs = [[AboutUsViewController alloc]initWithNibName:@"AboutUsViewController" bundle:nil];
[self.navigationController pushViewController:aboutUs animated:YES];
}
}
if (indexPath.section == 3) {
if (indexPath.row == 0) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否要退出登录" message:@"点击确认退出登录" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[AppDelegate appDelegate] quitAndShowLoginView];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alert animated:YES completion:^{
}];
}
}
}
- (void)copyNum:(id)sender{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = miJiaNumberLabel.text;
[SVProgressHUD setMinimumDismissTimeInterval:2];
[SVProgressHUD showSuccessWithStatus:@"复制成功"];
}
-(void)clearCacheSuccess{
cacheLabel.text = @"0MB";
[SVProgressHUD setMinimumDismissTimeInterval:2];
[SVProgressHUD showSuccessWithStatus:@"已清理"];
}
- (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