EditVC.m 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. //
  2. // EditVC.m
  3. // YBVideo
  4. //
  5. // Created by YunBao on 2018/6/14.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "EditVC.h"
  9. #import "EditCell.h"
  10. #import "EditHeader.h"
  11. #import "AFNetworking.h"
  12. #import "Utils.h"
  13. #import <SDWebImage/SDImageCache.h>
  14. #import <MobileCoreServices/MobileCoreServices.h>
  15. @import CoreLocation;
  16. @interface EditVC ()<TZImagePickerControllerDelegate,UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIPickerViewDelegate, UIPickerViewDataSource,CLLocationManagerDelegate> {
  17. UIImage *iconImage;
  18. MyTextField *name_tf;
  19. MyTextField *birth_tf;
  20. MyTextField *sex_tf;
  21. MyTextField *location_tf;
  22. MyTextField *signature_tf;
  23. UILabel *signature_num;
  24. UIView *cityPickBack;
  25. UIPickerView *cityPicker;
  26. //省市区-数组
  27. NSArray *province;
  28. NSArray *city;
  29. NSArray *district;
  30. //省市区-字符串
  31. NSString *provinceStr;
  32. NSString *cityStr;
  33. NSString *districtStr;
  34. NSDictionary *areaDic;
  35. NSString *selectedProvince;
  36. UIView *birthPickBack;
  37. UIDatePicker *birthPicker;
  38. NSString *birthStr;
  39. CLLocationManager *_lbsManager;
  40. NSString *normalProvince;
  41. NSString *normalCity;
  42. NSString *normalDistrict;
  43. }
  44. @property(nonatomic,assign)BOOL iconChange;
  45. @property(nonatomic,strong)UITableView *tableView;
  46. @property(nonatomic,strong)EditHeader *tabHeader;
  47. @end
  48. @implementation EditVC
  49. - (UIStatusBarStyle)preferredStatusBarStyle {
  50. if (@available(iOS 13.0,*)) {
  51. return UIStatusBarStyleDarkContent;
  52. }
  53. return UIStatusBarStyleDefault;
  54. }
  55. - (void)viewDidLoad {
  56. [super viewDidLoad];
  57. self.view.backgroundColor = UIColor.whiteColor;
  58. normalProvince = @"";
  59. normalCity = @"";
  60. normalDistrict = @"";
  61. self.iconChange = NO;
  62. self.titleL.text = YZMsg(@"编辑资料");
  63. self.rightBtn.hidden = NO;
  64. [self.rightBtn setTitle:YZMsg(@"保存") forState:0];
  65. self.subNavi.backgroundColor = UIColor.whiteColor;
  66. self.titleL.textColor = UIColor.blackColor;
  67. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  68. self.naviLine.hidden = NO;
  69. self.naviLine.backgroundColor = RGB(245, 245, 245);
  70. [self.view addSubview:self.tableView];
  71. [self.tableView setTableHeaderView:self.tabHeader];
  72. NSBundle *bundle = [NSBundle mainBundle];
  73. NSString *plistPath = [bundle pathForResource:@"area" ofType:@"plist"];
  74. areaDic = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
  75. NSArray *components = [areaDic allKeys];
  76. NSArray *sortedArray = [components sortedArrayUsingComparator: ^(id obj1, id obj2) {
  77. if ([obj1 integerValue] > [obj2 integerValue]) {
  78. return (NSComparisonResult)NSOrderedDescending;
  79. }
  80. if ([obj1 integerValue] < [obj2 integerValue]) {
  81. return (NSComparisonResult)NSOrderedAscending;
  82. }
  83. return (NSComparisonResult)NSOrderedSame;
  84. }];
  85. NSMutableArray *provinceTmp = [[NSMutableArray alloc] init];
  86. for (int i=0; i<[sortedArray count]; i++) {
  87. NSString *index = [sortedArray objectAtIndex:i];
  88. NSArray *tmp = [[areaDic objectForKey: index] allKeys];
  89. [provinceTmp addObject: [tmp objectAtIndex:0]];
  90. }
  91. //---> //rk_3-7 修复首次加载问题
  92. province = [[NSArray alloc] initWithArray: provinceTmp];
  93. NSString *index = [sortedArray objectAtIndex:0];
  94. //NSString *selected = [province objectAtIndex:0];
  95. selectedProvince = [province objectAtIndex:0];
  96. NSDictionary *proviceDic = [NSDictionary dictionaryWithDictionary: [[areaDic objectForKey:index]objectForKey:selectedProvince]];
  97. NSArray *cityArray = [proviceDic allKeys];
  98. NSDictionary *cityDic = [NSDictionary dictionaryWithDictionary: [proviceDic objectForKey: [cityArray objectAtIndex:0]]];
  99. //city = [[NSArray alloc] initWithArray: [cityDic allKeys]];
  100. NSArray *citySortedArray = [cityArray sortedArrayUsingComparator: ^(id obj1, id obj2) {
  101. if ([obj1 integerValue] > [obj2 integerValue]) {
  102. return (NSComparisonResult)NSOrderedDescending;//递减
  103. }
  104. if ([obj1 integerValue] < [obj2 integerValue]) {
  105. return (NSComparisonResult)NSOrderedAscending;//上升
  106. }
  107. return (NSComparisonResult)NSOrderedSame;
  108. }];
  109. NSMutableArray *m_array = [[NSMutableArray alloc] init];
  110. for (int i=0; i<[citySortedArray count]; i++) {
  111. NSString *index = [citySortedArray objectAtIndex:i];
  112. NSArray *temp = [[proviceDic objectForKey: index] allKeys];
  113. [m_array addObject: [temp objectAtIndex:0]];
  114. }
  115. city = [NSArray arrayWithArray:m_array];
  116. //<-----------
  117. NSString *selectedCity = [city objectAtIndex: 0];
  118. district = [[NSArray alloc] initWithArray: [cityDic objectForKey: selectedCity]];
  119. birthStr = [Config getUserBirth];
  120. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFiledEditChanged:) name:UITextFieldTextDidChangeNotification object:nil];
  121. [self location];
  122. }
  123. #pragma mark - textfield 监听字数变化
  124. -(void)textFiledEditChanged:(NSNotification *)noti {
  125. MyTextField *textField = (MyTextField *)noti.object;
  126. NSString *toBeString = textField.text;
  127. NSString *lang = [[[UITextInputMode activeInputModes]firstObject] primaryLanguage]; // 键盘输入模式
  128. if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写
  129. UITextRange *selectedRange = [textField markedTextRange];//获取高亮部分
  130. UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
  131. //没有高亮选择的字,则对已输入的文字进行字数统计和限制
  132. if (!position) {
  133. //签名tf
  134. if (textField == signature_tf) {
  135. if (toBeString.length > 20) {
  136. textField.text = [toBeString substringToIndex:20];
  137. //signature_num.text = [NSString stringWithFormat:@"%lu/20",(20-textField.text.length)];
  138. signature_num.text = [NSString stringWithFormat:@"%lu/20",textField.text.length];
  139. }else{
  140. //signature_num.text = [NSString stringWithFormat:@"%lu/20",(20-toBeString.length)];
  141. signature_num.text = [NSString stringWithFormat:@"%lu/20",toBeString.length];
  142. }
  143. }
  144. //昵称tf
  145. if (textField == name_tf) {
  146. if (toBeString.length > 8) {
  147. textField.text = [toBeString substringToIndex:8];
  148. [MBProgressHUD showPop:YZMsg(@"昵称最多可编辑8个字")];
  149. }
  150. }
  151. }else{
  152. //有高亮选择的字符串,则暂不对文字进行统计和限制
  153. }
  154. }else{
  155. // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况
  156. if (textField == signature_tf) {
  157. if (toBeString.length > 20) {
  158. textField.text = [toBeString substringToIndex:20];
  159. signature_num.text = [NSString stringWithFormat:@"%lu/20",textField.text.length];
  160. }else{
  161. signature_num.text = [NSString stringWithFormat:@"%lu/20",toBeString.length];
  162. }
  163. }
  164. if (textField == name_tf) {
  165. if (toBeString.length > 8) {
  166. textField.text = [toBeString substringToIndex:8];
  167. [MBProgressHUD showPop:YZMsg(@"昵称最多可编辑8个字")];
  168. }
  169. }
  170. }
  171. }
  172. #pragma mark - 保存信息
  173. -(void)clickSaveInfo {
  174. [self.view endEditing:YES];
  175. BOOL i_change = NO;
  176. //头像更改过
  177. if (_iconChange == YES) {
  178. i_change = YES;
  179. YBWeakSelf;
  180. //AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
  181. NSString *url = [purl stringByAppendingFormat:@"?service=User.updateAvatar&uid=%@&token=%@&lang=%@",[Config getOwnID],[Config getOwnToken],[YBLanguageTools serviceLang]];
  182. [[YBNetworking ybnetManager] POST:url parameters:nil headers:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  183. if (iconImage) {
  184. [formData appendPartWithFileData:[Utils compressImage:iconImage] name:@"file" fileName:[self getVideoNameBaseCurrentTime:@".png"] mimeType:@"image/jpeg"];
  185. }
  186. }progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  187. NSLog(@"-------%@",responseObject);
  188. NSArray *data = [responseObject valueForKey:@"data"];
  189. NSString *ret = [NSString stringWithFormat:@"%@",[responseObject valueForKey:@"ret"]];
  190. if ([ret isEqual:@"200"]) {
  191. NSNumber *number = [data valueForKey:@"code"] ;
  192. if([number isEqualToNumber:[NSNumber numberWithInt:0]]){
  193. weakSelf.iconChange = NO;
  194. //[[SDImageCache sharedImageCache] clearDisk];
  195. [[SDImageCache sharedImageCache]clearDiskOnCompletion:^{
  196. }];
  197. [[SDImageCache sharedImageCache] clearMemory];//可有可无
  198. NSString *info = [[data valueForKey:@"info"] firstObject];
  199. NSString *avatar = [info valueForKey:@"avatar"];
  200. NSString *avatar_thumb = [info valueForKey:@"avatar_thumb"];
  201. [Config saveUserAvatar:avatar];
  202. [Config saveUserAvatarThumb:avatar_thumb];
  203. //[MBProgressHUD showPop:YZMsg(@"更改成功")];
  204. }else if ([number isEqual:@"700"]) {
  205. [PublicObj tokenExpired:[data valueForKey:@"msg"]];
  206. }
  207. }else{
  208. [weakSelf.tabHeader.iconIV sd_setImageWithURL:[NSURL URLWithString:[Config getUserAvatar]]];
  209. [MBProgressHUD showPop:[responseObject valueForKey:@"msg"]];
  210. }
  211. }failure:^(NSURLSessionDataTask *task, NSError *error) {
  212. [weakSelf.tabHeader.iconIV sd_setImageWithURL:[NSURL URLWithString:[Config getUserAvatar]]];
  213. [MBProgressHUD showPop:YZMsg(@"上传失败")];
  214. }];
  215. }
  216. NSLog(@"name-%@===birth-%@===sex-%@===location-%@===signature-%@",name_tf.text,birth_tf.text,sex_tf.text,location_tf.text,signature_tf.text);
  217. //判断更改了那些信息
  218. NSMutableDictionary *m_dic = [NSMutableDictionary dictionary];
  219. //名字
  220. if (![name_tf.text isEqual:[Config getOwnNicename]]) {
  221. [m_dic setObject:name_tf.text forKey:@"user_nickname"];
  222. }
  223. //生日
  224. if (![birth_tf.text isEqual:[Config getUserBirth]]) {
  225. [m_dic setObject:birth_tf.text forKey:@"birthday"];
  226. }
  227. //性别
  228. NSString *sexStr;
  229. if ([sex_tf.text isEqual:YZMsg(@"男")]) {
  230. sexStr = @"1";
  231. }else{
  232. sexStr = @"2";
  233. }
  234. if (![sexStr isEqual:[Config getUserSex]]) {
  235. [m_dic setObject:sexStr forKey:@"sex"];
  236. }
  237. //地区
  238. if (![location_tf.text isEqual:[Config getUserHomeTown]]) {
  239. [m_dic setObject:provinceStr forKey:@"province"];
  240. [m_dic setObject:cityStr forKey:@"city"];
  241. [m_dic setObject:districtStr forKey:@"area"];
  242. }
  243. //签名
  244. if (![signature_tf.text isEqual:[Config getOwnSignature]]) {
  245. [m_dic setObject:signature_tf.text forKey:@"signature"];
  246. }
  247. if (![m_dic count]) {
  248. //没有更改任何信息
  249. i_change==YES ? [MBProgressHUD showPop:YZMsg(@"设置头像成功")]: [MBProgressHUD showPop:YZMsg(@"未修改资料")];
  250. if (i_change) {
  251. // [self.navigationController popViewControllerAnimated:YES];
  252. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  253. [self.navigationController popViewControllerAnimated:YES];
  254. });
  255. }
  256. return;
  257. }
  258. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:m_dic options:NSJSONWritingPrettyPrinted error:nil];
  259. NSString *jsonStr = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  260. NSString *saveUrl = [NSString stringWithFormat:@"User.updateFields&uid=%@&token=%@&fields=%@",[Config getOwnID],[Config getOwnToken],jsonStr];
  261. saveUrl = [saveUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  262. [YBNetworking postWithUrl:saveUrl Dic:nil Suc:^(int code, id info, NSString *msg) {
  263. if (code == 0) {
  264. if ([m_dic valueForKey:@"user_nickname"]) {
  265. //说明更改了-名字
  266. [Config saveOwnNicename:[NSString stringWithFormat:@"%@",[m_dic valueForKey:@"user_nickname"]]];
  267. }
  268. if ([m_dic valueForKey:@"birthday"]) {
  269. //说明更改了-生日
  270. [Config saveUserBirth:[NSString stringWithFormat:@"%@",[m_dic valueForKey:@"birthday"]]];
  271. }
  272. if ([m_dic valueForKey:@"sex"]) {
  273. //说明更改了-性别
  274. [Config saveUserSex:[NSString stringWithFormat:@"%@",[m_dic valueForKey:@"sex"]]];
  275. }
  276. if ([m_dic valueForKey:@"province"]) {
  277. //说明更改了-地址
  278. [Config saveUserHomeTown:[NSString stringWithFormat:@"%@%@%@",[m_dic valueForKey:@"province"],[m_dic valueForKey:@"city"],[m_dic valueForKey:@"area"]]];
  279. }
  280. if ([m_dic valueForKey:@"signature"]) {
  281. //说明更改了-签名
  282. [Config saveOwnSignature:[NSString stringWithFormat:@"%@",[m_dic valueForKey:@"signature"]]];
  283. }
  284. NSDictionary *ifnoDic = [info firstObject];
  285. [MBProgressHUD showPop:minstr([ifnoDic valueForKey:@"msg"])];
  286. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  287. [self.navigationController popViewControllerAnimated:YES];
  288. });
  289. }else{
  290. [MBProgressHUD showPop:msg];
  291. }
  292. } Fail:^(id fail) {
  293. }];
  294. }
  295. -(void)clickChangeBirth {
  296. if (!birthPickBack) {
  297. birthPickBack = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
  298. birthPickBack.backgroundColor = RGB_COLOR(@"#000000", 0.3);
  299. [self.view addSubview:birthPickBack];
  300. UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height-240, _window_width, 40)];
  301. titleView.backgroundColor = RGB_COLOR(@"#ececec", 1);
  302. [birthPickBack addSubview:titleView];
  303. UIButton *cancleBtn = [UIButton buttonWithType:0];
  304. cancleBtn.frame = CGRectMake(20, 0, 80, 40);
  305. cancleBtn.tag = 100;
  306. [cancleBtn setTitle:YZMsg(@"取消") forState:0];
  307. [cancleBtn setTitleColor:[UIColor blueColor] forState:0];
  308. [cancleBtn addTarget:self action:@selector(birthCancleOrSure:) forControlEvents:UIControlEventTouchUpInside];
  309. [titleView addSubview:cancleBtn];
  310. UIButton *sureBtn = [UIButton buttonWithType:0];
  311. sureBtn.frame = CGRectMake(_window_width-100, 0, 80, 40);
  312. sureBtn.tag = 101;
  313. [sureBtn setTitle:YZMsg(@"确定") forState:0];
  314. [sureBtn setTitleColor:[UIColor blueColor] forState:0];
  315. [sureBtn addTarget:self action:@selector(birthCancleOrSure:) forControlEvents:UIControlEventTouchUpInside];
  316. [titleView addSubview:sureBtn];
  317. birthPicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, _window_height-200, _window_width, 200)];
  318. if (@available(iOS 13.4,*)) {
  319. birthPicker.preferredDatePickerStyle = UIDatePickerStyleWheels;
  320. //设置样式后必须重新设置尺寸
  321. birthPicker.frame = CGRectMake(0, _window_height-200, _window_width, 200);
  322. }
  323. NSDate *currentDate = [NSDate date];
  324. [birthPicker setMaximumDate:currentDate];
  325. NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
  326. [formatter setDateFormat : @"yyyy-MM-dd" ];
  327. NSString *mindateStr = @"1950-01-01" ;
  328. NSDate *mindate = [formatter dateFromString :mindateStr];
  329. birthPicker.minimumDate = mindate;
  330. birthPicker.maximumDate=[NSDate date];
  331. [birthPicker addTarget:self action:@selector(oneDatePickerValueChanged:) forControlEvents:UIControlEventValueChanged ];
  332. birthPicker.datePickerMode = UIDatePickerModeDate;
  333. birthPicker.backgroundColor = [UIColor whiteColor];
  334. //设置为中文
  335. NSLocale *locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
  336. if (![lagType isEqual:ZH_CN]) {
  337. locale = [[NSLocale alloc]initWithLocaleIdentifier:@"en"];
  338. }
  339. birthPicker.locale =locale;
  340. [birthPickBack addSubview:birthPicker];
  341. }else{
  342. birthPickBack.hidden = NO;
  343. }
  344. }
  345. - (void)birthCancleOrSure:(UIButton *)button{
  346. if (button.tag == 100) {
  347. //return;
  348. }else{
  349. //未滑动peaker直接点击确定
  350. if (birthStr.length<=0||[birthStr isEqual:[Config getUserBirth]]) {
  351. NSDate *currentDate = [NSDate date];//获取当前时间,日期
  352. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  353. [dateFormatter setDateFormat:@"YYYY-MM-dd"];
  354. birthStr = [dateFormatter stringFromDate:currentDate];
  355. }
  356. birth_tf.text = birthStr;
  357. }
  358. birthPickBack.hidden = YES;
  359. }
  360. - (void)oneDatePickerValueChanged:(UIDatePicker *) sender {
  361. NSDate *select = [sender date]; // 获取被选中的时间
  362. NSDateFormatter *selectDateFormatter = [[NSDateFormatter alloc] init];
  363. [selectDateFormatter setDateFormat:@"YYYY-MM-dd"];
  364. birthStr = [selectDateFormatter stringFromDate:select]; // 把date类型转为设置好格式的string类型
  365. }
  366. -(void)clickChangeSex {
  367. RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:nil];
  368. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"男") complete:^{
  369. sex_tf.text = YZMsg(@"男");
  370. }];
  371. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"女") complete:^{
  372. sex_tf.text = YZMsg(@"女");
  373. }];
  374. [sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
  375. }];
  376. [sheet showSheet];
  377. }
  378. //城市选择
  379. -(void)clickChangeLocation {
  380. if (!cityPickBack) {
  381. cityPickBack = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
  382. cityPickBack.backgroundColor = RGB_COLOR(@"#000000", 0.3);
  383. [self.view addSubview:cityPickBack];
  384. UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height-240, _window_width, 40)];
  385. titleView.backgroundColor = RGB_COLOR(@"#ececec", 1);
  386. [cityPickBack addSubview:titleView];
  387. UIButton *cancleBtn = [UIButton buttonWithType:0];
  388. cancleBtn.frame = CGRectMake(20, 0, 80, 40);
  389. cancleBtn.tag = 100;
  390. [cancleBtn setTitle:YZMsg(@"取消") forState:0];
  391. [cancleBtn setTitleColor:[UIColor blueColor] forState:0];
  392. [cancleBtn addTarget:self action:@selector(cityCancleOrSure:) forControlEvents:UIControlEventTouchUpInside];
  393. [titleView addSubview:cancleBtn];
  394. UIButton *sureBtn = [UIButton buttonWithType:0];
  395. sureBtn.frame = CGRectMake(_window_width-100, 0, 80, 40);
  396. sureBtn.tag = 101;
  397. [sureBtn setTitle:YZMsg(@"确定") forState:0];
  398. [sureBtn setTitleColor:[UIColor blueColor] forState:0];
  399. [sureBtn addTarget:self action:@selector(cityCancleOrSure:) forControlEvents:UIControlEventTouchUpInside];
  400. [titleView addSubview:sureBtn];
  401. cityPicker = [[UIPickerView alloc]initWithFrame:CGRectMake(0, _window_height-200, _window_width, 200)];
  402. cityPicker.backgroundColor = [UIColor whiteColor];
  403. cityPicker.delegate = self;
  404. cityPicker.dataSource = self;
  405. cityPicker.showsSelectionIndicator = YES;
  406. [cityPicker selectRow: 0 inComponent: 0 animated: YES];
  407. [cityPickBack addSubview:cityPicker];
  408. [self setLocationAddress];
  409. }else{
  410. cityPickBack.hidden = NO;
  411. }
  412. }
  413. - (void)cityCancleOrSure:(UIButton *)button{
  414. if (button.tag == 100) {
  415. //return;
  416. }else{
  417. NSInteger provinceIndex = [cityPicker selectedRowInComponent: 0];
  418. NSInteger cityIndex = [cityPicker selectedRowInComponent: 1];
  419. NSInteger districtIndex = [cityPicker selectedRowInComponent: 2];
  420. provinceStr = [province objectAtIndex: provinceIndex];
  421. cityStr = [city objectAtIndex: cityIndex];
  422. districtStr = [district objectAtIndex:districtIndex];
  423. NSString *dizhi = [NSString stringWithFormat:@"%@%@%@",provinceStr,cityStr,districtStr];
  424. location_tf.text = dizhi;
  425. }
  426. cityPickBack.hidden = YES;
  427. }
  428. #pragma mark- Picker Data Source Methods
  429. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
  430. if (pickerView == cityPicker) {
  431. return 3;
  432. }
  433. return 0;
  434. }
  435. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  436. if (pickerView == cityPicker) {
  437. if (component == 0) {
  438. return [province count];
  439. }
  440. else if (component == 1) {
  441. return [city count];
  442. }
  443. else {
  444. return [district count];
  445. }
  446. }else{
  447. return 100;
  448. }
  449. }
  450. #pragma mark- Picker Delegate Methods
  451. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
  452. if (pickerView == cityPicker) {
  453. if (component == 0) {
  454. return [province objectAtIndex: row];
  455. }
  456. else if (component == 1) {
  457. return [city objectAtIndex: row];
  458. }
  459. else {
  460. return [district objectAtIndex: row];
  461. }
  462. }else{
  463. return nil;
  464. }
  465. }
  466. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
  467. if (pickerView == cityPicker) {
  468. if (component == 0) {
  469. selectedProvince = [province objectAtIndex: row];
  470. NSDictionary *tmp = [NSDictionary dictionaryWithDictionary: [areaDic objectForKey: [NSString stringWithFormat:@"%ld", row]]];
  471. NSDictionary *dic = [NSDictionary dictionaryWithDictionary: [tmp objectForKey: selectedProvince]];
  472. NSArray *cityArray = [dic allKeys];
  473. NSArray *sortedArray = [cityArray sortedArrayUsingComparator: ^(id obj1, id obj2) {
  474. if ([obj1 integerValue] > [obj2 integerValue]) {
  475. return (NSComparisonResult)NSOrderedDescending;//递减
  476. }
  477. if ([obj1 integerValue] < [obj2 integerValue]) {
  478. return (NSComparisonResult)NSOrderedAscending;//上升
  479. }
  480. return (NSComparisonResult)NSOrderedSame;
  481. }];
  482. NSMutableArray *array = [[NSMutableArray alloc] init];
  483. for (int i=0; i<[sortedArray count]; i++) {
  484. NSString *index = [sortedArray objectAtIndex:i];
  485. NSArray *temp = [[dic objectForKey: index] allKeys];
  486. [array addObject: [temp objectAtIndex:0]];
  487. }
  488. city = [[NSArray alloc] initWithArray: array];
  489. NSDictionary *cityDic = [dic objectForKey: [sortedArray objectAtIndex: 0]];
  490. district = [[NSArray alloc] initWithArray: [cityDic objectForKey: [city objectAtIndex: 0]]];
  491. [cityPicker selectRow: 0 inComponent: 1 animated: YES];
  492. [cityPicker selectRow: 0 inComponent: 2 animated: YES];
  493. [cityPicker reloadComponent: 1];
  494. [cityPicker reloadComponent: 2];
  495. } else if (component == 1) {
  496. NSString *provinceIndex = [NSString stringWithFormat: @"%ld", [province indexOfObject: selectedProvince]];
  497. NSDictionary *tmp = [NSDictionary dictionaryWithDictionary: [areaDic objectForKey: provinceIndex]];
  498. NSDictionary *dic = [NSDictionary dictionaryWithDictionary: [tmp objectForKey: selectedProvince]];
  499. NSArray *dicKeyArray = [dic allKeys];
  500. NSArray *sortedArray = [dicKeyArray sortedArrayUsingComparator: ^(id obj1, id obj2) {
  501. if ([obj1 integerValue] > [obj2 integerValue]) {
  502. return (NSComparisonResult)NSOrderedDescending;
  503. }
  504. if ([obj1 integerValue] < [obj2 integerValue]) {
  505. return (NSComparisonResult)NSOrderedAscending;
  506. }
  507. return (NSComparisonResult)NSOrderedSame;
  508. }];
  509. NSDictionary *cityDic = [NSDictionary dictionaryWithDictionary: [dic objectForKey: [sortedArray objectAtIndex: row]]];
  510. NSArray *cityKeyArray = [cityDic allKeys];
  511. district = [[NSArray alloc] initWithArray: [cityDic objectForKey: [cityKeyArray objectAtIndex:0]]];
  512. [cityPicker selectRow: 0 inComponent: 2 animated: YES];
  513. [cityPicker reloadComponent: 2];
  514. }
  515. }else{
  516. }
  517. }
  518. - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
  519. if (component == 0) {
  520. return 80;
  521. }
  522. else if (component == 1) {
  523. return 100;
  524. }
  525. else {
  526. return 115;
  527. }
  528. }
  529. - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
  530. UILabel *myView = nil;
  531. if (pickerView == cityPicker) {
  532. if (component == 0) {
  533. myView = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, _window_width/3, 30)];
  534. myView.textAlignment = NSTextAlignmentCenter;
  535. myView.text = [province objectAtIndex:row];
  536. myView.font = [UIFont systemFontOfSize:14];
  537. myView.backgroundColor = [UIColor clearColor];
  538. }
  539. else if (component == 1) {
  540. myView = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, _window_width/3, 30)];
  541. myView.textAlignment = NSTextAlignmentCenter;
  542. myView.text = [city objectAtIndex:row];
  543. myView.font = [UIFont systemFontOfSize:14];
  544. myView.backgroundColor = [UIColor clearColor];
  545. }
  546. else {
  547. myView = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, _window_width/3, 30)];
  548. myView.textAlignment = NSTextAlignmentCenter;
  549. myView.text = [district objectAtIndex:row];
  550. myView.font = [UIFont systemFontOfSize:14];
  551. myView.backgroundColor = [UIColor clearColor];
  552. }
  553. }
  554. return myView;
  555. }
  556. #pragma mark -
  557. #pragma mark - UITableViewDelegate,UITableViewDataSource
  558. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  559. return 1;
  560. }
  561. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  562. if (indexPath.row == 4) {
  563. //签名
  564. return 80;
  565. }else{
  566. return 60;
  567. }
  568. }
  569. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  570. return 5;
  571. }
  572. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  573. EditCell *cell = [EditCell cellWithTab:tableView andIndexPath:indexPath];
  574. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  575. cell.backgroundColor = UIColor.whiteColor;
  576. switch (indexPath.row) {
  577. case 0:{
  578. cell.nameTF.text = [Config getOwnNicename];
  579. name_tf = cell.nameTF;
  580. }break;
  581. case 1:{
  582. cell.birthTF.text = [Config getUserBirth];
  583. cell.birthTF.userInteractionEnabled = NO;
  584. birth_tf = cell.birthTF;
  585. }break;
  586. case 2:{
  587. if ([[Config getUserSex]isEqual:@"1"]) {
  588. cell.sexTF.text = YZMsg(@"男");
  589. }else{
  590. cell.sexTF.text = YZMsg(@"女");
  591. }
  592. cell.sexTF.userInteractionEnabled = NO;
  593. sex_tf = cell.sexTF;
  594. }break;
  595. case 3:{
  596. NSString *homeStr = [PublicObj checkNull:[Config getUserHomeTown]]?@"":[Config getUserHomeTown];
  597. if ([homeStr isEqual:@"城市未填写"]) {//不要翻译
  598. homeStr = @"";
  599. }
  600. cell.locationTF.text = homeStr;
  601. cell.locationTF.userInteractionEnabled = NO;
  602. location_tf = cell.locationTF;
  603. }break;
  604. case 4:{
  605. cell.signatoryTF.text = [Config getOwnSignature];
  606. //2020-6-20改为显示输入的字数
  607. //cell.numL.text = [NSString stringWithFormat:@"%lu/20",(20-cell.signatoryTF.text.length)];
  608. cell.numL.text = [NSString stringWithFormat:@"%lu/20",cell.signatoryTF.text.length];
  609. signature_num = cell.numL;
  610. signature_tf = cell.signatoryTF;
  611. }break;
  612. default:
  613. break;
  614. }
  615. return cell;
  616. }
  617. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  618. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  619. switch (indexPath.row) {
  620. case 0:{
  621. }break;
  622. case 1:{
  623. [self clickChangeBirth];
  624. NSLog(@"bitth");
  625. }break;
  626. case 2:{
  627. NSLog(@"sex");
  628. [self clickChangeSex];
  629. } break;
  630. case 3:{
  631. NSLog(@"location");
  632. [self clickChangeLocation];
  633. }break;
  634. case 4:{
  635. }break;
  636. default:
  637. break;
  638. }
  639. }
  640. - (void)didReceiveMemoryWarning {
  641. [super didReceiveMemoryWarning];
  642. }
  643. #pragma mark - UIImagePickerControllerDelegate
  644. //拍照
  645. -(void)clickTake {
  646. UIImagePickerController *imagePickerController = [UIImagePickerController new];
  647. imagePickerController.allowsEditing = YES;
  648. imagePickerController.delegate = self;
  649. imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  650. imagePickerController.allowsEditing = YES;
  651. imagePickerController.showsCameraControls = YES;
  652. imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
  653. //imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
  654. imagePickerController.modalPresentationStyle = 0;
  655. [self presentViewController:imagePickerController animated:YES completion:nil];
  656. }
  657. //选照
  658. -(void)clickSel {
  659. /*
  660. UIImagePickerController *imagePickerController = [UIImagePickerController new];
  661. imagePickerController.allowsEditing = YES;
  662. imagePickerController.delegate = self;
  663. imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  664. imagePickerController.allowsEditing = YES;
  665. imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
  666. [UIApplication sharedApplication].statusBarHidden = YES;
  667. if (@available(iOS 11, *)) {
  668. UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  669. }
  670. imagePickerController.modalPresentationStyle = 0;
  671. [self presentViewController:imagePickerController animated:YES completion:nil];
  672. */
  673. TZImagePickerController *imagePC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
  674. imagePC.preferredLanguage = [lagType isEqual:ZH_CN] ? @"zh-Hans":@"en";
  675. imagePC.showSelectBtn = NO;
  676. imagePC.allowPickingOriginalPhoto = NO;
  677. imagePC.oKButtonTitleColorNormal = Pink_Cor;
  678. imagePC.allowTakePicture = NO;
  679. imagePC.allowTakeVideo = NO;
  680. imagePC.allowPickingVideo = NO;
  681. imagePC.allowPickingMultipleVideo = NO;
  682. imagePC.modalPresentationStyle = 0;
  683. imagePC.allowCrop = YES;
  684. imagePC.cropRect = CGRectMake(0, (_window_height-_window_width)/2, _window_width, _window_width);
  685. [[[YBBaseAppDelegate sharedAppDelegate] topViewController]presentViewController:imagePC animated:YES completion:nil];
  686. }
  687. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto{
  688. _iconChange = YES;
  689. iconImage = photos[0];
  690. _tabHeader.iconIV.image = iconImage;
  691. }
  692. -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
  693. if (@available(iOS 11, *)) {
  694. UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  695. }
  696. _iconChange = YES;
  697. NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
  698. if ([type isEqualToString:@"public.image"]) {
  699. //先把图片转成NSData
  700. UIImage* image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
  701. iconImage = image;
  702. _tabHeader.iconIV.image = image;
  703. /*
  704. NSData *data;
  705. if (UIImagePNGRepresentation(image) == nil) {
  706. data = UIImageJPEGRepresentation(image, 1.0);
  707. }else{
  708. data = UIImagePNGRepresentation(image);
  709. }
  710. //图片保存的路径
  711. NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  712. NSFileManager *fileManager = [NSFileManager defaultManager];
  713. //把刚刚图片转换的data对象拷贝至沙盒中 并保存为image.png
  714. [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
  715. [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];
  716. //得到选择后沙盒中图片的完整路径
  717. NSString *filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath, @"/image.png"];
  718. NSURL *imageURL = [NSURL URLWithString:filePath];
  719. UIImage *image = [UIImage imageWithContentsOfFile:filePath];
  720. */
  721. [picker dismissViewControllerAnimated:YES completion:^{
  722. [UIApplication sharedApplication].statusBarHidden=NO;
  723. }];
  724. }
  725. }
  726. - (NSString *)getVideoNameBaseCurrentTime:(NSString *)suf {
  727. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  728. [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  729. NSString *nameStr = [[dateFormatter stringFromDate:[NSDate date]] stringByAppendingString:suf];
  730. return [NSString stringWithFormat:@"%@_IOS_avatar%@",[Config getOwnID],nameStr];
  731. }
  732. -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
  733. [picker dismissViewControllerAnimated:YES completion:^{
  734. [UIApplication sharedApplication].statusBarHidden=NO;
  735. }];
  736. }
  737. - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  738. if ([UIDevice currentDevice].systemVersion.floatValue < 11) {
  739. return;
  740. }
  741. if ([viewController isKindOfClass:NSClassFromString(@"PUPhotoPickerHostViewController")]) {
  742. [viewController.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  743. if (obj.frame.size.width < 42) {
  744. [viewController.view sendSubviewToBack:obj];
  745. *stop = YES;
  746. }
  747. }];
  748. }
  749. }
  750. #pragma mark - seg/get
  751. -(EditHeader *)tabHeader {
  752. if (!_tabHeader) {
  753. __weak EditVC *weakSelf = self;
  754. _tabHeader = [[[NSBundle mainBundle]loadNibNamed:@"EditHeader" owner:nil options:nil] objectAtIndex:0];
  755. _tabHeader.backgroundColor = UIColor.whiteColor;
  756. [_tabHeader.iconIV sd_setImageWithURL:[NSURL URLWithString:[Config getUserAvatar]]];
  757. _tabHeader.event = ^(id event) {
  758. [weakSelf showSheetView];
  759. };
  760. }
  761. return _tabHeader;
  762. }
  763. -(void)showSheetView {
  764. YBWeakSelf;
  765. RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:@""];
  766. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"相机") complete:^{
  767. [weakSelf clickTake];
  768. }];
  769. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"相册") complete:^{
  770. [weakSelf clickSel];
  771. }];
  772. [sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
  773. }];
  774. [sheet showSheet];
  775. }
  776. -(UITableView *)tableView{
  777. if (!_tableView) {
  778. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight, _window_width, _window_height-64-statusbarHeight-ShowDiff) style:UITableViewStyleGrouped];
  779. _tableView.dataSource = self;
  780. _tableView.delegate = self;
  781. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  782. _tableView.backgroundColor = UIColor.whiteColor;
  783. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  784. _tableView.showsVerticalScrollIndicator = NO;
  785. }
  786. return _tableView;
  787. }
  788. - (void)clickNaviRightBtn {
  789. [self clickSaveInfo];
  790. }
  791. #pragma mark -
  792. -(void)location{
  793. [[RKLBSManager shareManager]startLocation];
  794. [RKLBSManager shareManager].fromEdit = YES;
  795. [[RKLBSManager shareManager]locationComplete:^(NSArray *placemarks, NSArray<NSString *> *pcaArray) {
  796. normalProvince = pcaArray[0];
  797. normalCity = pcaArray[1];
  798. normalDistrict = pcaArray[2];
  799. }];
  800. }
  801. /*
  802. -(void)location{
  803. if (!_lbsManager) {
  804. _lbsManager = [[CLLocationManager alloc] init];
  805. [_lbsManager setDesiredAccuracy:kCLLocationAccuracyBest];
  806. _lbsManager.delegate = self;
  807. // 兼容iOS8定位
  808. SEL requestSelector = NSSelectorFromString(@"requestWhenInUseAuthorization");
  809. if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined && [_lbsManager respondsToSelector:requestSelector]) {
  810. [_lbsManager requestWhenInUseAuthorization]; //调用了这句,就会弹出允许框了.
  811. } else {
  812. [_lbsManager startUpdatingLocation];
  813. }
  814. }
  815. }
  816. - (void)stopLbs {
  817. [_lbsManager stopUpdatingHeading];
  818. _lbsManager.delegate = nil;
  819. _lbsManager = nil;
  820. }
  821. - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
  822. if (status == kCLAuthorizationStatusRestricted || status == kCLAuthorizationStatusDenied) {
  823. [self stopLbs];
  824. } else {
  825. [_lbsManager startUpdatingLocation];
  826. }
  827. }
  828. - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
  829. [self stopLbs];
  830. }
  831. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
  832. CLLocation *newLocatioin = locations[0];
  833. CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  834. [geocoder reverseGeocodeLocation:newLocatioin completionHandler:^(NSArray *placemarks, NSError *error) {
  835. if (!error) {
  836. CLPlacemark *placeMark = placemarks[0];
  837. NSString *addr = [NSString stringWithFormat:@"%@%@%@",placeMark.administrativeArea,placeMark.locality,placeMark.subLocality];
  838. NSLog(@"hhhhhhhh----:%@", addr);
  839. normalProvince =placeMark.administrativeArea;
  840. normalCity = placeMark.locality;
  841. normalDistrict = placeMark.subLocality;
  842. }
  843. }];
  844. [self stopLbs];
  845. }
  846. */
  847. -(void)setLocationAddress{
  848. int provinceIndex = 0;
  849. int cityIndex = 0;
  850. NSArray *components = [areaDic allKeys];
  851. NSArray *sortedArray = [components sortedArrayUsingComparator: ^(id obj1, id obj2) {
  852. if ([obj1 integerValue] > [obj2 integerValue]) {
  853. return (NSComparisonResult)NSOrderedDescending;
  854. }
  855. if ([obj1 integerValue] < [obj2 integerValue]) {
  856. return (NSComparisonResult)NSOrderedAscending;
  857. }
  858. return (NSComparisonResult)NSOrderedSame;
  859. }];
  860. NSMutableArray *provinceTmp = [[NSMutableArray alloc] init];
  861. for (int i=0; i<[sortedArray count]; i++) {
  862. NSString *index = [sortedArray objectAtIndex:i];
  863. NSArray *tmp = [[areaDic objectForKey: index] allKeys];
  864. [provinceTmp addObject: [tmp objectAtIndex:0]];
  865. }
  866. if (normalProvince.length > 0) {
  867. selectedProvince = normalProvince;
  868. for (int i = 0; i < province.count; i ++) {
  869. if ([normalProvince isEqual:province[i]]) {
  870. provinceIndex = i;
  871. NSString *index = [sortedArray objectAtIndex:i];
  872. NSDictionary *proviceDic = [NSDictionary dictionaryWithDictionary: [[areaDic objectForKey:index]objectForKey:normalProvince]];
  873. NSArray *cityArray = [proviceDic allKeys];
  874. // NSDictionary *cityDic = [NSDictionary dictionaryWithDictionary: [proviceDic objectForKey: [cityArray objectAtIndex:i]]];
  875. NSArray *citySortedArray = [cityArray sortedArrayUsingComparator: ^(id obj1, id obj2) {
  876. if ([obj1 integerValue] > [obj2 integerValue]) {
  877. return (NSComparisonResult)NSOrderedDescending;//递减
  878. }
  879. if ([obj1 integerValue] < [obj2 integerValue]) {
  880. return (NSComparisonResult)NSOrderedAscending;//上升
  881. }
  882. return (NSComparisonResult)NSOrderedSame;
  883. }];
  884. NSMutableArray *m_array = [[NSMutableArray alloc] init];
  885. for (int i=0; i<[citySortedArray count]; i++) {
  886. NSString *index = [citySortedArray objectAtIndex:i];
  887. NSArray *temp = [[proviceDic objectForKey: index] allKeys];
  888. [m_array addObject: [temp objectAtIndex:0]];
  889. }
  890. NSArray *cityArr = [NSArray arrayWithArray:m_array];
  891. city =[NSArray arrayWithArray:m_array];
  892. for (int j = 0; j < cityArr.count; j ++) {
  893. if ([normalCity isEqual:cityArr[j]]) {
  894. cityIndex = j;
  895. NSString *keys = [NSString stringWithFormat:@"%d",cityIndex];
  896. NSDictionary *dicssss = [NSDictionary dictionaryWithDictionary: [proviceDic objectForKey: keys]];
  897. NSString *selectedCity = [cityArr objectAtIndex: j];
  898. district = [[NSArray alloc] initWithArray: [dicssss objectForKey: selectedCity]];
  899. NSArray * districtArr = [[NSArray alloc] initWithArray: [dicssss objectForKey: selectedCity]];
  900. for (int k = 0; k <districtArr.count; k ++) {
  901. if ([normalDistrict isEqual:districtArr[k]]) {
  902. [cityPicker selectRow: provinceIndex inComponent: 0 animated: YES];
  903. [cityPicker reloadComponent: 1];
  904. [cityPicker selectRow: cityIndex inComponent: 1 animated: YES];
  905. [cityPicker reloadComponent: 2];
  906. [cityPicker selectRow: k inComponent: 2 animated: YES];
  907. }
  908. }
  909. }
  910. }
  911. }
  912. }
  913. }
  914. NSLog(@"province===:%@ \n city:%@ \ndistrict:%@",province,city,district);
  915. }
  916. @end