I'm trying to set the product options if images into UICollectionView with user interaction enabled so user can select the option he/she prefers before adding the product to the cart.
@IBOutlet weak var optionView: UIView!
optionView.translatesAutoresizingMaskIntoConstraints = false
var Y:CGFloat = -10
else if dict["type"].stringValue == "image" {
let imageOptionView = UICollectionView(frame: CGRect(x: 5, y: Y, width: self.optionView.frame.size.width - 10, height: 30))
imageOptionView.isUserInteractionEnabled = true
self.optionView.addSubview(imageOptionView)
imageOptionView.tag = 11000;
Y += 60;
let productOptionArray : JSON = JSON(dict["product_option_value"].arrayObject!)
let imagesArray:NSMutableArray = []
var internalY:CGFloat = 0
for j in 0..<productOptionArray.count {
let img = UIImageView(frame: CGRect(x: 5, y: internalY, width: imageOptionView.frame.size.width, height: 30))
let images = productOptionArray[j]["image"].stringValue
let data = NSData(contentsOf: NSURL(string: images)! as URL)
img.image = UIImage(data: data! as Data)
img.tag = j;
img.isUserInteractionEnabled = true
imageOptionView.addSubview(img)
internalY += 60;
imagesArray.add(img)
print ("Printing Images", images)
print ("Printing ImageView", imageOptionView)
print ("Printing One Image", img.image)
print ("Printing ImageArray", imagesArray)
}
Since it's a subview it should follow the main optionview Y position. Once I test the app and try to load the product page the app crashes.
EDIT: Thanks to @Sh_Khan posting an answer now I get a different error:
The behavior of the UICollectionViewFlowLayout is not defined because: the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values. The relevant UICollectionViewFlowLayout instance is , and it is attached to ; layer = ; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0}> collection view layout: . Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger. * Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.54.4/UICollectionView.m:5283 * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier catalogimage - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
It sounds we're having conflict with another images parsed from JSON