单军华
2018-04-18 de88ae127e305e0b153c327b073645f9353cace5
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
221
222
223
224
225
226
227
228
229
230
231
232
//
//  SettingPage.m
//  airtree
//
//  Created by WindShan on 2016/11/14.
//  Copyright © 2016年 Gloria. All rights reserved.
//
 
#import "SettingPage.h"
#import "ChangePwdPage.h"
//#import "CommonReqModel.h"
 
 
@interface SettingPage ()
{
 
}
@end
 
@implementation SettingPage
 
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    self.navigationController.navigationBarHidden = NO;
    
}
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"个人中心";
    [self setNavigationLeft:@"返回" sel:@selector(backAction)];
    
    
    self.userInfoTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-60) style:UITableViewStyleGrouped];
    self.userInfoTableView.delegate = self;
    self.userInfoTableView.dataSource = self;
    self.userInfoTableView.backgroundColor = [UIColor clearColor];
    self.userInfoTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.userInfoTableView.scrollsToTop = YES;
    //self.userInfoTableView.scrollEnabled = YES;
    [self.view addSubview:self.userInfoTableView];
 
}
 
-(void) backAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidDisappear:YES];
    
    [self.userInfoTableView reloadData];
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
 
//此处上面和下面 是设置 footerview
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 80;
}
 
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 80)];
    
    UIButton *quitLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quitLoginBtn.frame =CGRectMake(30, 50, SCREEN_WIDTH-60, 40);
    [quitLoginBtn.layer setMasksToBounds:YES];
    [quitLoginBtn.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
    quitLoginBtn.backgroundColor = RgbColor(84, 76, 155);/////色值自己改一下
    [quitLoginBtn setTitle:@"退出当前账号" forState:UIControlStateNormal];
    quitLoginBtn.userInteractionEnabled = YES;
    [quitLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [quitLoginBtn addTarget:self action:@selector(exitLoginAction) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:quitLoginBtn];
    
    return view;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"PersonCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    
    NSUInteger index = [indexPath row];
    
    switch (index)
    {
        case 0:
        {
            NSString *nickname = _loginUser[@"nickname"] == nil ? _loginUser[@"username"] : _loginUser[@"nickname"];
            
            cell.textLabel.text = @"昵称";
            cell.detailTextLabel.text = nickname;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
            break;
        case 1:
            cell.textLabel.text = @"修改密码";
            cell.detailTextLabel.text = @"";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            break;
        case 2:
            cell.textLabel.text = @"分享";
            cell.detailTextLabel.text = @"";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            break;
    }
    return cell;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
 
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger index = [indexPath row];
//    // 页面跳转
//    if(index == 0)
//    {
//        // 跳转昵称修改界面
//        ChangeNamePage * page = [[ChangeNamePage alloc] initIsFirstPage:NO];
//        [self.navigationController pushViewController:page animated:YES];
//    }
//    else if(index == 1)
//    {
//        // 跳转修改密码界面
//        ChangePwdPage * page = [[ChangePwdPage alloc] initIsFirstPage:NO];
//        [self.navigationController pushViewController:page animated:YES];
//    }
//    else if(index == 2)
//    {
//        // 跳转修改密码界面
//        ChangePwdPage * page = [[ChangePwdPage alloc] initIsFirstPage:NO];
//        [self.navigationController pushViewController:page animated:YES];
//    }
//    else
//    {
//        //TODO
//    }
}
 
#pragma mark - custom function begin
-(void)exitLoginAction
{
    NSString *path = [NSString stringWithFormat:@"/user/offline"];
    
//    CommonReqModel * model = [[CommonReqModel alloc] init];
//    model.userID = _loginUser[@"_id"];
//    
//    MKNetworkHost *host = [[MKNetworkHost alloc] initWithHostName:MORAL_API_BASE_PATH];
//    MKNetworkRequest *request = [host requestWithPath:path params:model.toDic httpMethod:HTTPPOST];
//    [request addCompletionHandler: ^(MKNetworkRequest *completedRequest)
//    {
//        NSString *response = [completedRequest responseAsString];
//        NSError *error = [completedRequest error];
//        NSData *data = [completedRequest responseData];
//        
//        BaseResModel * model = [Global GetResModel:data error:&error];
//        if(model == nil)
//        {
//            [Global alertMessageEx:[error localizedDescription] title:@"退出失败" okTtitle:nil cancelTitle:@"确定" delegate:self];
//        }
//        else
//        {
//            switch (model.code) {
//                case 0:
//                {
//                    [MBProgressHUD showTipsMsg:model.desc toView:self.navigationController.view];
//                    
//                    [UserDefault setObject:@"0" forKey:@"isLogin"];
//                    [UserDefault setObject:nil forKey:@"user_id"];
//                    
//                    _loginUser = nil;
//                    
//                    [GetAppDelegate showLoginPage];
//                }
//                    break;
//                    
//                default:
//                {
//                    [Global alertMessageEx:model.desc title:@"退出失败" okTtitle:nil cancelTitle:@"确定" delegate:self];
//                }
//                    break;
//            }
//        }
//    }];
//    
//    [host startRequest:request];
    
    
    [UserDefault setObject:@"0" forKey:@"isLogin"];
    [UserDefault setObject:nil forKey:@"user_id"];
    
    _loginUser = nil;
    
    [GetAppDelegate showLoginPage];
}
 
#pragma mark - custom function end
 
/*
#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