UICollectionView for self-calibration of cells. Insert / reload

Writing this question as my last resort, stuck on this for several days. I am trying to implement size cells for a UICollectionView using FlowLayout . Everything seems to work fine until I reladData() or insertItemsAtIndexPaths() , being at the bottom of the collection.

This is my cell:

 class FooFoo: UICollectionViewCell { var label: UILabel! var text: String! { didSet { label.text = text } } override init(frame: CGRect) { super.init(frame: frame) setupView() setupConstraints() } required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } func setupView() { self.contentView.backgroundColor = UIColor.yellowColor() label = ({ let view = UILabel() view.setTranslatesAutoresizingMaskIntoConstraints(false) self.contentView.addSubview(view) return view })() } func setupConstraints() { self.contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-100-[childView]-100-|", options: nil, metrics: nil, views: ["childView": label])) self.contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-100-[childView]-100-|", options: nil, metrics: nil, views: ["childView": label])) } 

}

This is the definition of CollectionView :

  collectionView = ({ let layout = UICollectionViewFlowLayout() layout.minimumLineSpacing = 1 layout.estimatedItemSize = CGSize(width: 300, height: 300) let view = UICollectionView(frame: self.view.frame, collectionViewLayout: layout) view.dataSource = self view.delegate = self view.registerClass(FooFoo.self, forCellWithReuseIdentifier: "Cell") view.backgroundColor = UIColor.clearColor() self.view.addSubview(view) return view })() 

This is dataSource :

 func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return items.count } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! FooFoo cell.text = "FooBar: \(indexPath.item)" return cell } 

After I extracted additional elements, I tried both to insert a new array of indices and reload the data, and the result is the same - a broken layout.

I also tried replacing estimatedItemSize with itemSize , and it really worked very well, so I'm pretty sure that this is because the cells are for self-calibration.

This is the result:

Insert bathc of items on Fetch breaks layout

+7
swift uicollectionview uicollectionviewlayout flowlayout collectionview
source share

No one has answered this question yet.

See related questions:

186
UICollectionView Self Sizing Cells with Auto Layout
4
Adding a custom UIViewcontroller for the routine is programmatic, but receiving the error message "Unable to convert type value ..."
one
Swift error - using cell of implicit type 'cell' - Collection View
one
Problems with casting cell types to remove
0
Programmatically placing the View collection in view
0
Fast vertical UICollectionView inside UITableView
0
Multiple view of UICollection in single scrolling of UIView does not work while loading data from cells from API
0
uibutton in viewview collection action duplicator
0
UICollectionView in UIScrollView loading the whole cell
0
Reload Data Collection View Inside Cell (Swift) Tabular View

All Articles