问题
I have a UIPicker View with 2 components. The title for the rows of each component are in relationship, that is, the texts and number of the rows in the 2nd component will change according to the selected row in the 1st component.
Now, the problem is, when I scroll the two components together, my app crashes.
I guess the reason is that when the 1st component is being scrolled, the supposed number of rows in 2nd component keeps changing, but meantime, the UIPickerView is asking for the title and number for the 2nd component, then it crashes.
But I haven't found any method that can be used to judge whether a component is being scrolled. So I can't find the correct time to reject the request of the pickerView's delegate and datasource for the 2nd component.
What am I supposed to do?
回答1:
Im running to the same issue and I'm thinking about conjunction of two options into one string which than could be placed into an array for UIPicker. So there will be only 1 component. Maybe you should do the same?
Another solution that might be helpful I'd found is here
But the basic idea for 2 depended components picker is having 2 arrays: 1st for left component and 2nd for the right. Each time user makes choice on left component the array for the right side repopulates according to the left side choice.
来源:https://stackoverflow.com/questions/9601144/uipickerview-with-two-components-crashes-when-scrolling-both