0

我刚开始迁移到 iOS 7 并在我的应用程序中发现了几个关于 UIPickerView 的问题。原因是我使用 UIPickerView 的子视图来自定义它的背景和样式。我正在记录 UIpickerview 的子视图计数,它始终为 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;
}

我 iOS 6.1,计数始终为 9。

编辑 1:另一个区别:波纹管代码在 iOS 7 上崩溃并且在 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;
}

编辑 2:_pickerView.showsSelectionIndicator = NO;

对iOS 7没有任何感情。

有人可以解释它是如何工作的吗?

4

0 回答 0