-
-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed an issue when initial selections applied to picker with different number of rows for different components. #113
Conversation
Hi. First of all: Thanks for your contribution again with great explanation of the problem and solution!. Also, you can check very similar case in example:
|
@venj any updates? |
@skywinder In my example, the first button clicked is just like the "musical scale"example. In the example, no matter what item is selected in component 0, component 1 will always have the same items. In that example, initial selections will work as long as they not beyond picker items' bound. In my example, the second button clicked will also work. But the difference is, when selection in component 0 changed, items in component 1 will change accordingly. Since initial selections are (0,0), picker work fine. If the last button clicked, set up is the same to second button. But initial selections are (1, 2). The selections are not beyond the bounds, but the app still crashes. As I made this example, I found my pull request will not completely fix the bug, only prevent the app from crashing. I am looking into the issue now. |
@venj Wow. Thank you for such detail and high-quality explanation! By the way: |
// pickerView:didSelectRow:inComponent: automatically, so we manually call it. | ||
if ( [_delegate respondsToSelector:@selector(pickerView:didSelectRow:inComponent:)] ) | ||
{ | ||
[_delegate pickerView:pv didSelectRow:row inComponent:i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your call [_delegate pickerView:pv didSelectRow:row inComponent:i];
just reload component from delegate method.
@venj this bug can be solved in more universal way:
Actually it will do the same thing (reloadComponents and update number of rows from delegate, thus app will not crash in the future This is more explicit way for the same job. |
I create separate issue #121 for the bug, that I described above. But as you said: this fix prevent the app from crashing. And then try to fix other issues. |
Scenario
For example, the titles for two pickerView components are like this:
If the initial selections for pickerview are
@[@(0), @(0)]
, there is no problem. But when initial selections are@[@(1), @(2)]
, there will be an app crash due toNSAssert([pv numberOfRowsInComponent:i] > row, @"Number of sections not match");
in- configuredPickerView
.Reason
I'm not very sure of the actual reason, but likely the reason is: set selected index for picker will not automatically call this
UIPickerView
delegate- pickerView:didSelectRow:inComponent:
. In our case, we have different number of rows in different components, and we have to update the second component when selection is changed in the first component, before we set the second selection. If not, we will crash the app if the selection is beyond the range of rows in first selection in our case.Solution
A manual call to
- pickerView:didSelectRow:inComponent:
delegate will fix the problem.