UIPickerView 在 iOS 7 + 版本中不显示图像

UIPickerView not showing images in iOS 7 + versions

我正在尝试 运行 我的应用程序在 iOS 7+ 版本中遇到一个问题

我有 UIPickerview 正确显示低于 iOS 7 的图像,但在 iOS 7+ 中整个选择器视图都乱七八糟。这就是我想要实现的目标

  1. 我在 Viewload 中有一组图像视图
  2. 正在尝试在 ViewForRow 方法中显示相同的内容。请检查下面的代码

    //In ViewDidLoad()
     NSArray *box12names = [[NSArray alloc] initWithObjects:@"Black",@"Brown",@"Red",@"Orange",@"Yellow",@"Green",nil];
    
    self.box1_views = [[NSMutableArray alloc] initWithCapacity:10]; 
    
    // From code below , Box1_Black, Box1_Brown etc... are my png images in APP
    
    for (NSString *str in box12names) {
    NSString *filename = [[NSString alloc] initWithFormat:@"Box1_%@.png",str];
    UIImage *image = [UIImage imageNamed:filename];
    UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
    
    [self.box1_views addObject:imageview];
    [filename release];
    [imageview release];
    
    }
    
     [self.box1_views release];
    
    self.box2_views = [[NSMutableArray alloc] initWithCapacity:10]; 
    
    for (NSString *str in box12names) {
    NSString *filename = [[NSString alloc] initWithFormat:@"Box2_%@.png",str];
    UIImageView *imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:filename]];
    
    [self.box2_views addObject:imageview];
    [filename release];
    [imageview release];
    
    }
    
    [self.box2_views release];
    
    [box12names release];
    
    
    //In PickerViewDelegate method
    
    -(UIView *)pickerView:(UIPickerView *)pickerView
       viewForRow:(NSInteger)row
     forComponent:(NSInteger)component reusingView:(UIView *)view
    
    {
    
    NSString *arrayName = [[NSString alloc] initWithFormat:@"box%d_views", component +1];
    
    NSArray *array = [self valueForKey:arrayName];
    
    UIView *tempview = [array objectAtIndex:row];
    
    [arrayName release];
    
    return tempview;
    
    }
    
    
    
    //Here my picker view is displaying wierdly with iOS 7+ version whereas works good with iOS 6
    

请帮忙

我认为你没有在 pickerview 的重用中添加 imageview 的子视图 view.So 在 pickerView:viewForRow 方法中尝试以下行:

tempView.addSubview(imageView);

问题已解决 -

{
NSString *arrayName = [[NSString alloc] initWithFormat:@"band%d_views", component +1];
NSArray *array = [self valueForKey:arrayName];
//UIView *tempview = [array objectAtIndex:row];
UIView *tempview=[[UIView alloc] init];
[tempview setBackgroundColor:[UIColor colorWithPatternImage:[[array objectAtIndex:row] image]]];

[arrayName release];
return tempview;
}