{"action":"created","issue":{"url":"https://api.github.com/repos/Akkyie/AKPickerView/issues/44","labels_url":"https://api.github.com/repos/Akkyie/AKPickerView/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/Akkyie/AKPickerView/issues/44/comments","events_url":"https://api.github.com/repos/Akkyie/AKPickerView/issues/44/events","html_url":"https://github.com/Akkyie/AKPickerView/issues/44","id":57630773,"number":44,"title":"reloadData pulls in new data, but spacing for old data persists","user":{"login":"brucegreig","id":46364,"avatar_url":"https://avatars.githubusercontent.com/u/46364?v=3","gravatar_id":"","url":"https://api.github.com/users/brucegreig","html_url":"https://github.com/brucegreig","followers_url":"https://api.github.com/users/brucegreig/followers","following_url":"https://api.github.com/users/brucegreig/following{/other_user}","gists_url":"https://api.github.com/users/brucegreig/gists{/gist_id}","starred_url":"https://api.github.com/users/brucegreig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brucegreig/subscriptions","organizations_url":"https://api.github.com/users/brucegreig/orgs","repos_url":"https://api.github.com/users/brucegreig/repos","events_url":"https://api.github.com/users/brucegreig/events{/privacy}","received_events_url":"https://api.github.com/users/brucegreig/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-13T17:49:40Z","updated_at":"2015-02-16T12:27:45Z","closed_at":null,"body":"I've got an AKPickerView which changes depending on user settings. It is in a recipe conversion tool and displays cups, grams (g) or ounces (oz) depending user settings. If user selects different units, then I change the data source array for the picker.\r\n\r\nChanging the array works fine, and the correct list of items appears according to the unit (cup/g/oz) selected by user.\r\n\r\nBut it seems that the spacing between items is dictated by the array first loaded. If I change the array, then the new items are displayed, but the spacing is wrong and the selected item gets forced off centre (at least, I think that's why it is not centered).\r\n\r\nLooks fine on first display:\r\n\r\n![screen shot 2015-02-13 at 17 41 44](https://cloud.githubusercontent.com/assets/46364/6192222/adc155f4-b3a7-11e4-92e8-51a6a783d076.png)\r\n\r\nBut after changing data in that picker, it goes a bit wonky:\r\n\r\n![screen shot 2015-02-13 at 17 41 22](https://cloud.githubusercontent.com/assets/46364/6192264/079d049c-b3a8-11e4-809d-9ccf9891d057.png)\r\n\r\nI can work around it by using items with very similar character lengths in each data set, but is there a way to force the picker to take into account the length of the items in the new data so that items are spaced out correctly? Any help much appreciated, thank you so much!\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Akkyie/AKPickerView/issues/comments/74501336","html_url":"https://github.com/Akkyie/AKPickerView/issues/44#issuecomment-74501336","issue_url":"https://api.github.com/repos/Akkyie/AKPickerView/issues/44","id":74501336,"user":{"login":"brucegreig","id":46364,"avatar_url":"https://avatars.githubusercontent.com/u/46364?v=3","gravatar_id":"","url":"https://api.github.com/users/brucegreig","html_url":"https://github.com/brucegreig","followers_url":"https://api.github.com/users/brucegreig/followers","following_url":"https://api.github.com/users/brucegreig/following{/other_user}","gists_url":"https://api.github.com/users/brucegreig/gists{/gist_id}","starred_url":"https://api.github.com/users/brucegreig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brucegreig/subscriptions","organizations_url":"https://api.github.com/users/brucegreig/orgs","repos_url":"https://api.github.com/users/brucegreig/repos","events_url":"https://api.github.com/users/brucegreig/events{/privacy}","received_events_url":"https://api.github.com/users/brucegreig/received_events","type":"User","site_admin":false},"created_at":"2015-02-16T12:27:45Z","updated_at":"2015-02-16T12:27:45Z","body":"I've isolated the cause. In some cases I programatically select first item in picker. (I do this to handle case where user has just changed their settings from one unit to another, leaving their previous picker selection out of range, as there are fewer items in the oz array than in the g array, for example). Then I reload the picker. If I remove that step (of programatically selecting an item in the picker before reloading the picker) then picker displays correctly.\r\n\r\nNow I just need to figure out how to handle case where picker array is changed to a smaller size leaving selected item out of range.\r\n\r\nI'll figure it out, but code below demonstrates what I mean if you are interested!\r\n\r\n```\r\n\r\n- (void)viewDidLoad {\r\n    [super viewDidLoad];\r\n    [self displayPicker];\r\n}\r\n\r\n-(void)viewDidAppear:(BOOL)animated {\r\n   // Need to use viewDidAppear, so that pickers updated when user returns from a separate Settings screen\r\n\r\n    // Force selection to first item in picker, to handle case where user had previously selected an item which is out of range of new array. (e.g. '29 inch' selected, then units changed to 'cm'. This step causes picker layout to get messed up. Comment out next line to resolve layout, but then we are exposed to out-of-range error on reloading the picker    \r\n    [self.testPicker selectItem:0 animated:NO];\r\n    [self displayPicker];   \r\n}\r\n\r\n-(void)displayPicker {\r\n    NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];\r\n    if ([settings stringForKey:@\"Units\"] == nil)\r\n    {\r\n        [settings setObject:@\"in\" forKey:@\"Units\"];\r\n        NSLog(@\"Unit selection null so insert default\");\r\n    }\r\n    \r\n    self.testPicker.delegate = self;\r\n    self.testPicker.dataSource = self;\r\n    self.testPicker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;\r\n    [self.view addSubview:self.testPicker];\r\n    self.testPicker.font = [UIFont fontWithName:@\"HelveticaNeue-Light\" size:20];\r\n    self.testPicker.highlightedFont = [UIFont fontWithName:@\"HelveticaNeue\" size:20];\r\n    self.testPicker.interitemSpacing = 20.0;\r\n    self.testPicker.fisheyeFactor = 0.001;\r\n    self.testPicker.pickerViewStyle = AKPickerViewStyle3D;\r\n    self.testPicker.hidden = NO;\r\n    \r\n    if ([[settings stringForKey:@\"Units\"]  isEqual: @\"in\"])\r\n    {\r\n        \r\n        self.testPickerItems = @[@\"1 inch\",\r\n                              @\"2 inch\",\r\n                              @\"3 inch\",\r\n                              @\"4 inch\",\r\n                              @\"5 inch\",\r\n                              @\"6 inch\",\r\n                              @\"7 inch\",\r\n                              @\"8 inch\",\r\n                              @\"9 inch\",\r\n                              @\"10 inch\",\r\n                              @\"11 inch\",\r\n                              @\"12 inch\",\r\n                              @\"13 inch\",\r\n                              @\"14 inch\",\r\n                              @\"15 inch\",\r\n                              @\"16 inch\",\r\n                              @\"17 inch\",\r\n                              @\"18 inch\",\r\n                              @\"19 inch\",\r\n                              @\"20 inch\",\r\n                              @\"21 inch\",\r\n                              @\"22 inch\",\r\n                              @\"23 inch\",\r\n                              @\"24 inch\",\r\n                              @\"25 inch\",\r\n                              @\"26 inch\",\r\n                              @\"27 inch\",\r\n                              @\"28 inch\",\r\n                              @\"29 inch\",\r\n                              @\"30 inch\",\r\n                              @\"31 inch\",\r\n                              @\"32 inch\",\r\n                              @\"33 inch\",\r\n                              @\"34 inch\",\r\n                              @\"35 inch\",\r\n                              @\"36 inch\",\r\n                              @\"37 inch\",\r\n                              @\"38 inch\"\r\n                              ];\r\n    }\r\n    \r\n    if ([[settings stringForKey:@\"Units\"]  isEqual: @\"cm\"])\r\n    {\r\n     \r\n // Note that this array is smaller than the inches array\r\n        \r\n        self.testPickerItems = @[@\"8cm\",\r\n                              @\"9cm\",\r\n                              @\"10cm\",\r\n                              @\"11cm\",\r\n                              @\"12cm\",\r\n                              @\"13cm\",\r\n                              @\"14cm\",\r\n                              @\"15cm\"];\r\n    }\r\n\r\n    [self.testPicker reloadData];\r\n}\r\n```\r\n"}}