|
//
// userInfoSexCell.m
// ThePaperDemo
//
// Created by scar1900 on 14/12/11.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "userInfoSexCell.h"
@interface userInfoSexCell()
@property(nonatomic,strong)UIButton *maleButton;
@property(nonatomic,strong)UIButton *femaleButton;
@end
@implementation userInfoSexCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.pushIcon.hidden = YES;
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self addSubview:self.maleButton];
[self addSubview:self.femaleButton];
[self layoutSubViews];
}
return self;
}
- (void)needrefreshSubNightMode {
[_maleButton setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal];
[_femaleButton setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal];
}
- (void)layoutSubViews {
[self.titleLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.top);
make.left.equalTo(self.left).offset(10);
make.width.mas_equalTo(@50);
}];
[self.maleButton makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.top);
make.left.equalTo(self.left).offset(100);
make.bottom.equalTo(self.lineView.top);
make.width.mas_equalTo(@40);
}];
[self.maleButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -40, 0, 25)];
[self.maleButton setImageEdgeInsets:UIEdgeInsetsMake(15, 20, 15, 0)];
[self.femaleButton makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.top);
make.left.equalTo(self.maleButton.right).offset(38);
make.bottom.equalTo(self.lineView.top);
make.width.mas_equalTo(@40);
}];
[self.femaleButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -40, 0, 25)];
[self.femaleButton setImageEdgeInsets:UIEdgeInsetsMake(15, 20, 15, 0)];
}
- (UIButton*)maleButton {
if (!_maleButton) {
_maleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_maleButton setTitle:@"男" forState:UIControlStateNormal];
[_maleButton setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal];
[_maleButton setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateSelected];
[_maleButton setImage:Image(@"login/personSex.png") forState:UIControlStateNormal];
[_maleButton setImage:Image(@"login/personSex_s.png") forState:UIControlStateSelected];
_maleButton.titleLabel.textAlignment = NSTextAlignmentLeft;
_maleButton.selected = NO;
[_maleButton addTarget:self action:@selector(selectMale:) forControlEvents:UIControlEventTouchUpInside];
}
_maleButton.titleLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
return _maleButton;
}
- (UIButton*)femaleButton {
if (!_femaleButton) {
_femaleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_femaleButton setTitle:@"女" forState:UIControlStateNormal];
[_femaleButton setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal];
[_femaleButton setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateSelected];
[_femaleButton setImage:Image(@"login/personSex.png") forState:UIControlStateNormal];
[_femaleButton setImage:Image(@"login/personSex_s.png") forState:UIControlStateSelected];
_femaleButton.titleLabel.textAlignment = NSTextAlignmentLeft;
_femaleButton.selected = NO;
[_femaleButton addTarget:self action:@selector(selectFemale:) forControlEvents:UIControlEventTouchUpInside];
}
_femaleButton.titleLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
return _femaleButton;
}
- (void)setSex:(NSString *)sexStr {
_sex = sexStr;
if ([sexStr intValue] == 0) {
self.maleButton.selected = YES;
self.femaleButton.selected = NO;
}else {
self.maleButton.selected = NO;
self.femaleButton.selected = YES;
}
}
- (void)selectMale:(UIButton*)btn {
if (btn.selected) {
return;
}
NSDictionary *dic = @{@"sex":@"0"};
__weak UIButton *femaleBtn = self.femaleButton;
__weak UIButton *maleBtn = btn;
[Remote doJsonActionWithBlock:0 requestUrl:editUserInfoURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]);
NSString *lastLoginType = [TPUserDefault instance].userBO.loginType;
user.loginType = lastLoginType;
[TPUserDefault instance].userBO = user;
ShowMessage(@"修改成功", YES);
maleBtn.selected = !maleBtn.selected;
if (maleBtn.selected) {
femaleBtn.selected = NO;
}
}else {
ShowTextMessage(message);
}
}];
}
- (void)selectFemale:(UIButton*)btn {
if (btn.selected) {
return;
}
NSDictionary *dic = @{@"sex":@"1"};
__weak UIButton *maleBtn = self.maleButton;
__weak UIButton *femaleBtn = btn;
[Remote doJsonActionWithBlock:0 requestUrl:editUserInfoURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]);
NSString *lastLoginType = [TPUserDefault instance].userBO.loginType;
user.loginType = lastLoginType;
[TPUserDefault instance].userBO = user;
ShowMessage(@"修改成功", YES);
femaleBtn.selected = !femaleBtn.selected;
if (femaleBtn.selected) {
maleBtn.selected = NO;
}
}else {
ShowTextMessage(message);
}
}];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|