Skip to content
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 more than one ActionSheetCustomPicker is used in a ViewController #108

Merged
merged 1 commit into from
Dec 9, 2014

Conversation

venj
Copy link

@venj venj commented Dec 9, 2014

How the issue happened

Since user should implement UIPickerView datasource methods in their own view controller for ActionSheetCustomPicker, when there's only one ActionSheetCustomPicker instance, there will be no problem. But in some rare cases, there are two or more ActionSheetCustomPicker instances (or mixed use with pure UIPickerView), the problem will appear.

In Data Source like this:

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if (pickerView == self.customPickerOne.pickerView) {
        // code...
        return XXX;
    }
    if (pickerView == self.customPickerTwo.pickerView) {
        // code...
        return YYY;
    }
    if (pickerView == self.customPickerThree.pickerView) {
        // code...
        return ZZZ;
    }
    ...
}
// Similar for other datasource methods.
...

When datasource methods are called, self.customPickerOne.pickerView is still nil. So, if there's only one picker, we don't have to differenciate between pickerviews, datasources provides data happily. But with multiple picker, if self.customPickerOne.pickerView is nil, we have no other ways to provide correct data to pickers seperately.

Solution

Since we know the cause, the solution is easy. Just assign the pickerview to self.pickerView immediately after its creation in - configuredPickerView for ActionSheetCustomPicker, so when datasource is called, the pickerView reference won't be nil. Problem solved.

@skywinder
Copy link
Owner

Very hard-to-find bug. Thanks for the fix! 👍

skywinder added a commit that referenced this pull request Dec 9, 2014
Fixed an issue when more than one ActionSheetCustomPicker is used in a ViewController
@skywinder skywinder merged commit 3bd3203 into skywinder:master Dec 9, 2014
@skywinder skywinder added the bug label Dec 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants