ios - CountryPicker UIPickerView calls subclassed method instead of its own -


so have problem using 2 uipickerview controls in 1 viewcontroller. using countrypicker found here https://github.com/nicklockwood/countrypicker show nice country picker user can select or hers country, , country code or hers phone number. want limit number of countries in 1 of pickers , show countries in other picker. when show 2 pickers, seems 1 has countrypicker type using overriden method -countriesofoperation customcountrypicker class.

i have tried storyboard , programatically init 2 pickers without success. can see i've tried remove first picker before showing second 1 , vice versa, won't fix it.

what reason setting *countryselectionpickerview countrypicker, still uses overriden method customcountrypicker? object of type countrypicker, still shows short countries list.

customcountrypicker.h

#import <countrypicker/countrypicker.h>  @interface customcountrypicker : countrypicker  /// returns dictionary of country names, keyed country code. +(nsdictionary<nsstring *, nsstring *> *)countrynamesbycode;  @end 

customcountrypicker.m

#import "customcountrypicker.h"  @implementation customcountrypicker  -(instancetype)initwithframe:(cgrect)frame {     return [super initwithframe:frame]; }  +(nsdictionary *)countriesofoperation {     nsdictionary *countries = @{ @"dk": @"denmark",                                  @"de": @"germany",                                  @"gb": @"great britain",                                  @"fr": @"france",                                  @"no": @"norway",                                  @"ch": @"switzerland"                                 };     return countries; }  +(nsdictionary *)countrynamesbycode {     nsdictionary *countries = [self countriesofoperation];     static nsdictionary *_countrynamesbycode = nil;     if (!_countrynamesbycode)     {         nsmutabledictionary *namesbycode = [nsmutabledictionary dictionary];         (nsstring *code in [nslocale isocountrycodes])         {             if([countries valueforkey:code]) {                 nsstring *countryname = [[nslocale currentlocale] displaynameforkey:nslocalecountrycode value:code];                  //workaround simulator bug                 if (!countryname)                 {                     countryname = [[nslocale localewithlocaleidentifier:@"en_us"] displaynameforkey:nslocalecountrycode value:code];                 }                 countryname = [countryname stringbyappendingstring:@" xxx"];                 namesbycode[code] = countryname ?: code;             }         }         _countrynamesbycode = [namesbycode copy];     }     return _countrynamesbycode; } 

someviewcontroller.h

#import <countrypicker/countrypicker.h> ... 

someviewcontroller.m

#import "customcountrypicker.h"  @interface someviewcontroller () <countrypickerdelegate>  @property (nonatomic, weak) iboutlet uiview *countrypickerview; @property (nonatomic, weak) iboutlet uiview *customcountrypickerview; @property (nonatomic, strong) countrypicker *countryselectionpickerview; @property (nonatomic, strong) customcountrypicker *customcountryselectionpickerview;  -(ibaction)countryselection:(id)sender {  [[[uiapplication sharedapplication] keywindow] endediting:yes]; uibutton *senderbutton = (uibutton *)sender;  if(senderbutton.tag == 101) {     [uiview animatewithduration:0.2 delay:0.0 options:0 animations:^{         self.countrypickerview.hidden = true;         [self.countryselectionpickerview removefromsuperview];         [self.customcountryselectionpickerview removefromsuperview];         self.customcountryselectionpickerview = [[customcountrypicker alloc] initwithframe:cgrectmake(0, 44, 375, 216)];         self.customcountryselectionpickerview.tag = 11;         self.customcountryselectionpickerview.delegate = self;         [self.customcountrypickerview addsubview:self.customcountryselectionpickerview];         self.customcountrypickerview.hidden = false;         self.customcountrypickerview.frame = cgrectmake(0, screen_height - 260, screen_width, 260);     } completion:nil];      // update user country  // select user country phone code } else if(senderbutton.tag == 102) {     [uiview animatewithduration:0.2 delay:0.0 options:0 animations:^{         self.customcountrypickerview.hidden = true;         [self.countryselectionpickerview removefromsuperview];         [self.customcountryselectionpickerview removefromsuperview];         self.countryselectionpickerview = [[countrypicker alloc] initwithframe:cgrectmake(0, 44, 375, 216)];         self.countryselectionpickerview.tag = 12;         self.countryselectionpickerview.delegate = self;         [self.countrypickerview addsubview:self.countryselectionpickerview];         self.countrypickerview.hidden = false;         self.countrypickerview.frame = cgrectmake(0, screen_height - 260, screen_width, 260);     } completion:nil]; } 

this because library using static variables both custom subclass , original countrypicker share data. can remove static keyword _countrynames, _countrycodes, _countrynamesbycode , _countrycodesbyname , should work.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -