123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // CountryCodeViewController.m
- // Artimenring
- //
- // Created
- // Copyright (c) 2015 BaH Cy. All rights reserved.
- //
- #import "SKSelectAreaViewController.h"
- #define COUNTRY_CODE @"code"
- #define COUNTRY_EN @"en"
- #define COUNTRY_ZH @"zh"
- @interface SKSelectAreaViewController ()<UITableViewDataSource, UITableViewDelegate> {
- NSMutableArray* mCodeArray;
- NSString* mLanguageKey;
- }
- @property (nonatomic, weak) IBOutlet UITableView *tableview;
- @end
- @implementation SKSelectAreaViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- //获取当前设备语言
- NSArray *appLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
- NSString *languageName = [appLanguages objectAtIndex:0];
- if ([languageName isStartWithString:COUNTRY_ZH])
- mLanguageKey = COUNTRY_ZH;
- else
- mLanguageKey = COUNTRY_EN;
-
- mCodeArray = [NSMutableArray new];
- mCodeArray = [EUtil getCountryCodeArray];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:NO];
- self.title = NSLocalizedString(@"CountryC.Title", nil);
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- self.title = @"";
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return mCodeArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *cellID = @"CountryCodeCellID";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
- if(cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
- }
-
- NSMutableDictionary* dic = mCodeArray[indexPath.row];
- cell.textLabel.text = [dic[mLanguageKey] description];
- cell.detailTextLabel.text = [NSString stringWithFormat:@"+%@",[dic[COUNTRY_CODE] description]];
- cell.accessoryType = UITableViewCellAccessoryNone;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
- NSMutableDictionary* dic = mCodeArray[indexPath.row];
- NSString* code = [NSString stringWithFormat:@"%@",[dic[COUNTRY_CODE] description]];
- [self setSelectArea:code];
- [[DataManager shared] showSKLoginViewController];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 50;
- }
- - (void)setSelectArea:(NSString*)code {
- //0:大陆 1:除大陆外的所有国家和地区
- if ([code isEqualToString:@"86"] || [code isEqualToString:@"+86"]) {
- [ServerManager setServerCategory:4];
- [UserDataHelper setLoginType:0];
- } else {
- [ServerManager setServerCategory:3];
- [UserDataHelper setLoginType:1];
- }
- }
- @end
|