IVTEditMySexViewController.m
4.48 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
//
// IVTEditMySexViewController.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/24.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTEditMySexViewController.h"
@interface IVTEditMySexViewController ()
{
UIButton *maleButton;
UIButton *femaleButton;
NSString *currentSelectSexString;
}
@end
@implementation IVTEditMySexViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setNavigationBar];
//男
maleButton = [UIButton buttonWithType:UIButtonTypeCustom];
maleButton.frame = CGRectMake(0, 0, kScreenWidth, 50);
[maleButton setTitle:@"男" forState:UIControlStateNormal];
[maleButton setTitleColor:UIColorFromRGBAlphaHex(0x5A5A5A, 1.0) forState:UIControlStateNormal];
[maleButton setTitleColor:UIColorFromRGBAlphaHex(0xD31863, 1.0) forState:UIControlStateSelected];
maleButton.backgroundColor = [UIColor whiteColor];
[maleButton addTarget:self action:@selector(doMaleButton) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:maleButton];
UIImageView *line = [[UIImageView alloc]init];
line.frame = CGRectMake(10, 50, kScreenWidth-20, 0.4);
line.alpha = 0.4;
line.backgroundColor = UIColorFromRGBAlphaHex(0x5A5A5A, 1.0);
[self.view addSubview:line];
//女
femaleButton = [UIButton buttonWithType:UIButtonTypeCustom];
femaleButton.frame = CGRectMake(0, 51, kScreenWidth, 50);
[femaleButton setTitle:@"女" forState:UIControlStateNormal];
[femaleButton setTitleColor:UIColorFromRGBAlphaHex(0x5A5A5A, 1.0) forState:UIControlStateNormal];
[femaleButton setTitleColor:UIColorFromRGBAlphaHex(0xD31863, 1.0) forState:UIControlStateSelected];
femaleButton.backgroundColor = [UIColor whiteColor];
[femaleButton addTarget:self action:@selector(doFemaleButton) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:femaleButton];
currentSelectSexString = [IVTAccountTool getSex];
if ([currentSelectSexString length]==0 || [currentSelectSexString isEqualToString:@"unknown"]) {
currentSelectSexString = @"female";
}
if ([currentSelectSexString isEqualToString:@"male"]) {
maleButton.selected = YES;
femaleButton.selected = NO;
}
else if ([currentSelectSexString isEqualToString:@"female"]){
maleButton.selected = NO;
femaleButton.selected = YES;
}
else{
maleButton.selected = NO;
femaleButton.selected = NO;
}
}
- (void)setNavigationBar{
self.navigationItem.title = @"性别";
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(doSave:)];
rightBarButton.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = rightBarButton;
}
- (void)doMaleButton{
maleButton.selected = YES;
femaleButton.selected = NO;
currentSelectSexString = @"male";
}
- (void)doFemaleButton{
maleButton.selected = NO;
femaleButton.selected = YES;
currentSelectSexString = @"female";
}
- (void)doSave:(UIBarButtonItem *)barBtnItem{
barBtnItem.enabled = NO;
[HUDUtil showLoading];
[[IVTNetworkAPIClient sharedClient] modifySex:currentSelectSexString success:^(NSDictionary *successData) {
[IVTAccountTool setSex:currentSelectSexString];
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeSex" object:nil];
if (self.editSuccessBlock) {
self.editSuccessBlock(currentSelectSexString);
}
[HUDUtil showSuccess:@"修改成功"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
} error:^(NSDictionary *successData) {
NSString *msg = successData[@"description"];
[HUDUtil showError:msg];
barBtnItem.enabled = YES;
} failure:^(NSError *failureError) {
[HUDUtil showError:@"网络异常"];
barBtnItem.enabled = YES;
}];
}
- (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