From ae022343a7c2930481f5ef96db4c417985bc4bfb Mon Sep 17 00:00:00 2001 From: Nicolas Vaezi-Nejad Date: Sun, 19 Jul 2015 21:48:59 +0200 Subject: [PATCH] Selected Item is out of bounds. When data changes and the picker is reload, selected item index can be out of bounds. To prevent that, I check in reloadData method the number of items in the picker view if it's bigger than selected item index. If this index is out, the picker don't scroll. --- AKPickerView/AKPickerView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AKPickerView/AKPickerView.swift b/AKPickerView/AKPickerView.swift index 9869533..d619c40 100644 --- a/AKPickerView/AKPickerView.swift +++ b/AKPickerView/AKPickerView.swift @@ -415,7 +415,7 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD self.invalidateIntrinsicContentSize() self.collectionView.collectionViewLayout.invalidateLayout() self.collectionView.reloadData() - if self.dataSource != nil && self.dataSource!.numberOfItemsInPickerView(self) > 0 { + if self.dataSource != nil && self.dataSource!.numberOfItemsInPickerView(self) > 0 && self.dataSource!.numberOfItemsInPickerView(self) > self.selectedItem { self.selectItem(self.selectedItem, animated: false, notifySelection: false) } }