【问题标题】:UIPickerView not showing images in iOS 7 + versionsUIPickerView 在 iOS 7 + 版本中不显示图像
【发布时间】:2016-12-13 05:22:14
【问题描述】:

我正在尝试在 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
    

请帮忙

【问题讨论】:

    标签: ios objective-c uipickerview uipickerviewdelegate


    【解决方案1】:

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

    tempView.addSubview(imageView);
    

    【讨论】:

    • 把viewDidiLoad中的imageView放到ViewforRow,
    • 请记住,如果您需要多于 1 种方法中的 imageView,请在 .m 文件中声明 imageview @interfave
    • 视图中的代码确实加载了:` NSArray *arrImage = @[@"box1.png", @"box2.png", @"box3.png", @"box4.png", @ "box5.png"]; // 在委托中包含图像的名称代码: ` UIView *tempView = [UIView new];// 如果需要,给框架 UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:arrImage[row]]]; [tempView addSubview:imgView];返回临时视图;`
    • 在上面试试这个可能会有所帮助,如果评论完全搞砸了,很抱歉。
    • 谢谢蒂努。我实际上尝试使用 UIColor colorwithPatternIMage 添加图像,它就像我预期的那样工作
    【解决方案2】:

    问题已解决 -

    {
    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      相关资源
      最近更新 更多