iOS newbie here. I'm using collection view controller with many cells and some of the cells on the bottom are cut off (not being displayed) as I scroll to the bottom.
I tried implementing UICollectionViewDelegateFlowLayout
protocol.
I also tried setting
self.view.frame.size.height
. However, I can only set the self.view.frame.size.height
to be something smaller like 200 but when I try to go above the default size, the screen doesn't get longer.
Is there a default constraint that I'm missing? Also would autolayout solve the problem?
Thanks!
EDIT:
I tried to add contraints - like doing self.view.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 8).isActive = true but not sure what are the parameter values should be for "equalTo". My goal is to add contraints to the main view in the view controller.
here is my code - thanks in advance!
class ViewController: UICollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()
// self.clearsSelectionOnViewWillAppear = false
self.view.frame.size.height = 1500
// Register cell classes
self.myCollectionView!.register(TableCell.self, forCellWithReuseIdentifier: "tableCell")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 200)
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return 8
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "tableCell", for: indexPath) as! TableCell
cell.contentView.backgroundColor = UIColor.blue
return cell
}
}
class TableCell : UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}