0

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

我有 UIPickerview 为低于 iOS 7 的版本正确显示图像,但在 iOS 7+ 中,整个选择器视图都搞砸了。这就是我想要实现的目标

  1. 我在 Viewload 中有一系列 imageViews
  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
    

请帮忙

4

2 回答 2

0

我认为您没有在 pickerview 的重用视图中添加 imageview 的子视图。所以在pickerView:viewForRow方法中尝试以下行:

tempView.addSubview(imageView);
于 2016-12-13T06:07:15.963 回答
0

问题解决了 -

{
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;
}
于 2016-12-13T06:32:30.627 回答