Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Fix issue when the selectedItem is greater than the new data source #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions AKPickerViewSample/AKPickerView/AKPickerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,13 @@ - (void)reloadData
[self invalidateIntrinsicContentSize];
[self.collectionView.collectionViewLayout invalidateLayout];
[self.collectionView reloadData];
if ([self.dataSource numberOfItemsInPickerView:self]) {
[self selectItem:self.selectedItem animated:NO notifySelection:NO];
}
NSUInteger count = [self.dataSource numberOfItemsInPickerView:self];
if (count > 0 ) {
if (self.selectedItem >= count) {
_selectedItem = count - 1;
}
[self selectItem:self.selectedItem animated:NO notifySelection:NO];
}
}

- (CGFloat)offsetForItem:(NSUInteger)item
Expand Down