我刚开始迁移到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没有任何感情。
有人可以解释它是如何运作的吗?