SKSelectAreaViewController.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // CountryCodeViewController.m
  3. // Artimenring
  4. //
  5. // Created
  6. // Copyright (c) 2015 BaH Cy. All rights reserved.
  7. //
  8. #import "SKSelectAreaViewController.h"
  9. #define COUNTRY_CODE @"code"
  10. #define COUNTRY_EN @"en"
  11. #define COUNTRY_ZH @"zh"
  12. @interface SKSelectAreaViewController ()<UITableViewDataSource, UITableViewDelegate> {
  13. NSMutableArray* mCodeArray;
  14. NSString* mLanguageKey;
  15. }
  16. @property (nonatomic, weak) IBOutlet UITableView *tableview;
  17. @end
  18. @implementation SKSelectAreaViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. //获取当前设备语言
  23. NSArray *appLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
  24. NSString *languageName = [appLanguages objectAtIndex:0];
  25. if ([languageName isStartWithString:COUNTRY_ZH])
  26. mLanguageKey = COUNTRY_ZH;
  27. else
  28. mLanguageKey = COUNTRY_EN;
  29. mCodeArray = [NSMutableArray new];
  30. mCodeArray = [EUtil getCountryCodeArray];
  31. }
  32. - (void)viewWillAppear:(BOOL)animated{
  33. [super viewWillAppear:animated];
  34. [self.navigationController setNavigationBarHidden:NO];
  35. self.title = NSLocalizedString(@"CountryC.Title", nil);
  36. }
  37. - (void)viewWillDisappear:(BOOL)animated {
  38. [super viewWillDisappear:animated];
  39. self.title = @"";
  40. }
  41. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  42. return mCodeArray.count;
  43. }
  44. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  45. static NSString *cellID = @"CountryCodeCellID";
  46. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
  47. if(cell == nil) {
  48. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
  49. }
  50. NSMutableDictionary* dic = mCodeArray[indexPath.row];
  51. cell.textLabel.text = [dic[mLanguageKey] description];
  52. cell.detailTextLabel.text = [NSString stringWithFormat:@"+%@",[dic[COUNTRY_CODE] description]];
  53. cell.accessoryType = UITableViewCellAccessoryNone;
  54. return cell;
  55. }
  56. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  57. [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
  58. NSMutableDictionary* dic = mCodeArray[indexPath.row];
  59. NSString* code = [NSString stringWithFormat:@"%@",[dic[COUNTRY_CODE] description]];
  60. [self setSelectArea:code];
  61. [[DataManager shared] showSKLoginViewController];
  62. }
  63. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  64. return 50;
  65. }
  66. - (void)setSelectArea:(NSString*)code {
  67. //0:大陆 1:除大陆外的所有国家和地区
  68. if ([code isEqualToString:@"86"] || [code isEqualToString:@"+86"]) {
  69. [UserDataHelper setSelectArea:0];
  70. } else {
  71. [UserDataHelper setSelectArea:1];
  72. }
  73. }
  74. @end