UIPickerview's subviews count is always 3 in iOS 7?

前提是你 提交于 2019-12-11 20:32:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!