Skip to content

Commit

Permalink
Selected Item is out of bounds.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ferannor committed Jul 19, 2015
1 parent 58a9948 commit ae02234
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion AKPickerView/AKPickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit ae02234

Please sign in to comment.