我使用一个UIPickerView与从Xib加载的自定义视图.
我使用的方法
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
从UIPickerViewDelegate重用我的视图.
使用iOS 6,我的UIPickerview工作完美,我的意见重复使用.
自从iOS 7以来,reusingView总是为零,所以我需要为每行加载NIB(我有250行).我的意见是做一些治疗,所以它可以占用一小部分内存,但x250 =大的内存泄漏.
为了确定问题是什么,我用UILabel做了一个简单的项目:
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel *label = (UILabel *)view; if(view == nil) { label = [[UILabel alloc] initWithFrame:CGRectMake(0,pickerView.frame.size.width,76)]; } else { NSLog(@"*******************************************************"); } NSLog(@"Current inndex : %i",row); label.text = [NSString stringWithFormat:@"TITRE %i",row]; return label; }
使用iOS 6,我的观点被正确重复使用:
2013-12-17 14:27:25.395 EssaiReusedViewPicker[261:907] Current inndex
: 220 2013-12-17 14:27:25.396 EssaiReusedViewPicker[261:907]
******************************************************* 2013-12-17 14:27:25.397 EssaiReusedViewPicker[261:907] Current inndex : 221
2013-12-17 14:27:25.404 EssaiReusedViewPicker[261:907]
******************************************************* 2013-12-17 14:27:25.407 EssaiReusedViewPicker[261:907] Current inndex : 222
2013-12-17 14:27:25.409 EssaiReusedViewPicker[261:907]
******************************************************* 2013-12-17 14:27:25.410 EssaiReusedViewPicker[261:907] Current inndex : 223
2013-12-17 14:27:25.411 EssaiReusedViewPicker[261:907]
******************************************************* 2013-12-17 14:27:25.412 EssaiReusedViewPicker[261:907] Current inndex : 224
2013-12-17 14:27:25.414 EssaiReusedViewPicker[261:907]
******************************************************* 2013-12-17 14:27:25.415 EssaiReusedViewPicker[261:907] Current inndex : 225
2013-12-17 14:27:25.420 EssaiReusedViewPicker[261:907]
******************************************************* 2013-12-17 14:27:25.424 EssaiReusedViewPicker[261:907] Current inndex : 227
2013-12-17 14:27:25.425 EssaiReusedViewPicker[261:907]
但是在iOS 7中,这是一个全新的故事:
2013-12-17 14:36:09.555 EssaiReusedViewPicker[7209:70b] Current inndex : 0 2013-12-17 14:36:09.557 EssaiReusedViewPicker[7209:70b] Current inndex : 1 2013-12-17 14:36:09.557 EssaiReusedViewPicker[7209:70b] Current inndex : 2 2013-12-17 14:36:09.560 EssaiReusedViewPicker[7209:70b] Current inndex : 0 2013-12-17 14:36:09.560 EssaiReusedViewPicker[7209:70b] Current inndex : 1 2013-12-17 14:36:09.561 EssaiReusedViewPicker[7209:70b] Current inndex : 2 2013-12-17 14:36:09.563 EssaiReusedViewPicker[7209:70b] Current inndex : 0 2013-12-17 14:36:09.563 EssaiReusedViewPicker[7209:70b] Current inndex : 1 2013-12-17 14:36:09.564 EssaiReusedViewPicker[7209:70b] Current inndex : 2 2013-12-17 14:36:09.566 EssaiReusedViewPicker[7209:70b] Current inndex : 0 2013-12-17 14:36:09.567 EssaiReusedViewPicker[7209:70b] Current inndex : 1 2013-12-17 14:36:09.567 EssaiReusedViewPicker[7209:70b] Current inndex : 2 2013-12-17 14:36:09.568 EssaiReusedViewPicker[7209:70b] Current inndex : 1 2013-12-17 14:36:09.568 EssaiReusedViewPicker[7209:70b] Current inndex : 2 2013-12-17 14:36:09.569 EssaiReusedViewPicker[7209:70b] Current inndex : 0 2013-12-17 14:36:09.569 EssaiReusedViewPicker[7209:70b] Current inndex : 1 2013-12-17 14:36:14.172 EssaiReusedViewPicker[7209:70b] Current inndex : 3 2013-12-17 14:36:14.350 EssaiReusedViewPicker[7209:70b] Current inndex : 3 2013-12-17 14:36:14.351 EssaiReusedViewPicker[7209:70b] Current inndex : 2 2013-12-17 14:36:14.367 EssaiReusedViewPicker[7209:70b] Current inndex : 4 2013-12-17 14:36:14.667 EssaiReusedViewPicker[7209:70b] Current inndex : 4 2013-12-17 14:36:14.668 EssaiReusedViewPicker[7209:70b] Current inndex : 3 2013-12-17 14:36:14.700 EssaiReusedViewPicker[7209:70b] Current inndex : 5 2013-12-17 14:36:15.067 EssaiReusedViewPicker[7209:70b] Current inndex : 5 2013-12-17 14:36:15.067 EssaiReusedViewPicker[7209:70b] Current inndex : 4 2013-12-17 14:36:15.083 EssaiReusedViewPicker[7209:70b] Current inndex : 6 2013-12-17 14:36:15.367 EssaiReusedViewPicker[7209:70b] Current inndex : 6 2013-12-17 14:36:15.367 EssaiReusedViewPicker[7209:70b] Current inndex : 5 2013-12-17 14:36:15.400 EssaiReusedViewPicker[7209:70b] Current inndex : 7 2013-12-17 14:36:16.416 EssaiReusedViewPicker[7209:70b] Current inndex : 7
那怎么了? iOS或…?