问题
I just started to migrate to iOS 7 and found several issues concerning UIPickerView in my app. And the reason is that I used the subviews of UIPickerView to customize it's background and style. I am logging the subviews count of UIpickerview and it's always is 3:
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent: (NSInteger)component
{
return 22;
}
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel* label = [[UILabel alloc]init];
label.frame = CGRectMake(152, 3,100, 16);
label.text = @"test";
NSLog(@"count is %i",_pickerView.subviews.count);
return label;
}
I iOS 6.1, the count is always 9.
Edit 1: Another difference: The bellow code crashes on iOS 7 and works without any problems on iOS 6.
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel* label = [[UILabel alloc]init];
label.frame = CGRectMake(152, 3,100, 16);
label.text = @"test";
if(row > 3){
UIView* view = [pickerView viewForRow:3 forComponent:0]; // crash in iOS 7
}
NSLog(@"count is %i",_pickerView.subviews.count);
return label;
}
Edit 2: _pickerView.showsSelectionIndicator = NO;
has not any affection on iOS 7.
Can someone explain how it works?
来源:https://stackoverflow.com/questions/18843780/uipickerviews-subviews-count-is-always-3-in-ios-7