Cells of CollectionView don't fit in screen

2019-08-27 17:54发布

问题:

I have CollectionView in cell of TableView:

Constraints for cell in CollectionView

When I run app f.e. on iPhone 5s I see (cell doesn't fit at screen):

But after scroll down and up I see:

I know about reuse, but how to show cell from start as must (fit to screen)?

回答1:

You Need to reaload your Collection View

In your TableViewCell Impleament Method

    func draw(_ rect: CGRect)
    {

// here you have to reaload your collectionView
        super.draw(rect)
    self.collectionView.realodData()

    }

refresh your TableCell By Calling its DrawRect Method

optional func tableView(_ tableView: UITableView, 
            willDisplay cell: UITableViewCell, 
               forRowAt indexPath: IndexPath)
{
  cell.setNeedsDisplay()
}

i hope this will work for you,