Scrollview仅第一次加载图像,然后不显示图像

时间:2018-06-22 12:15:08

标签: swift swift3 uiscrollview

您好,所以我可以选择汽车的来源(欧洲,亚洲,美国) 因此,我想用相关的品牌图片填充其下的滚动视图

到目前为止,它只有第一次才有效,所以如果我选择亚洲,我会获得亚洲品牌,但是如果我决定改变这一点并选择美国人,它将不会加载图像

我检查了数组是否填充了不同的图像集,并且确实添加了添加子视图图像的循环,也进行了迭代

所以我不知道问题所在

代码如下:

                 let subViews = self.brands.subviews
                 for subview in subViews{
                     subview.removeFromSuperview()
                }

                var brandimages = [UIImage]()
                if(self.subcattext == "Car Origin: European"){
                brandimages = self.euro
                }else if(self.subcattext == "Car Origin: American"){
                brandimages = self.amer
                }else if(self.subcattext == "Car Origin: Asian"){
                brandimages = self.asia
                }
                else{ }
                print(brandimages.count)
                for i in 0..<brandimages.count{
                    let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.brandTapped(tapGestureRecognizer:)))
                    let imageView = UIImageView()
                    imageView.image = brandimages[i]
                    let xPos = self.view.frame.width/4 * CGFloat(i)
                    imageView.frame = CGRect(x: xPos+5, y: self.brands.frame.midY, width: self.view.frame.width/5, height: self.view.frame.width/5 )
                    imageView.layer.cornerRadius = 20.0
                    imageView.borderWidth =  1
                    imageView.borderColor = UIColor.gray
                    imageView.clipsToBounds = true
                    imageView.shadowRadius = 5;
                    imageView.shadowOpacity = 0.5;
                    imageView.isUserInteractionEnabled = true
                    imageView.addGestureRecognizer(tapGestureRecognizer)

                    self.brands.contentSize.width = self.view.frame.width/4 * CGFloat(i + 1)
                    self.brands.addSubview(imageView)
                   // self.brands.refreshControl?.beginRefreshing()

                }

0 个答案:

没有答案