0

I have a table view and collection view to display image. Table view for vertical scroll and collection view for horizontal scroll. The image is displayed as full screen for the device. But when I scroll vertically half of previous cell is displayed and half of next cell is displayed. I used Table view constant is 0 to superview on all 4 constraints.

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return myTableView.frame.size.height;
}

To return the height of the cell but even this is causing same issue.

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = self.myTableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell
    return cell
}

This table view cell contains collection view

class TableViewCell: UITableViewCell,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
    
 func setUpCollectionView(){
    let layout = UICollectionViewFlowLayout()
    layout.scrollDirection = .horizontal
    collectionView = UICollectionView(frame: .zero,collectionViewLayout: layout)
    collectionView?.register(VideoCollectionViewCell.self, forCellWithReuseIdentifier: VideoCollectionViewCell.identifier)
    collectionView?.isPagingEnabled = true
    collectionView?.dataSource = self
    collectionView?.delegate = self
    self.contentView.addSubview(collectionView!)
    collectionView?.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate([
        collectionView!.topAnchor.constraint(equalTo: contentView.topAnchor),
        collectionView!.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
        collectionView!.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
        collectionView!.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
    ])
}

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: self.frame.width, height: self.frame.height)
    }
}

This is my implementation, I don't want images to be displayed on half/half portion. I am trying to show it on full screen. Can anyone tell me why this is happening?

iron
  • 715
  • 1
  • 6
  • 15

1 Answers1

0

you need only UICollectionView display list images and set property scroll horizontal in UICollectionViewFlowLayout

 myCollectionView.dataSource = self
    myCollectionView.delegate = self
    myCollectionView.contentMode = .scaleAspectFill
   //  scroll the images page by page, set property isPagingEnabled is true
    myCollectionView.isPagingEnabled = true
    
    let layout = UICollectionViewFlowLayout()
    // set sroll horizontal here
    layout.scrollDirection = .horizontal
    myCollectionView.collectionViewLayout = layout
Geo
  • 61
  • 1
  • 6
  • I have updated my config to collection view. Can you have a look please? – iron Sep 26 '21 at 11:14
  • If you want image display and scroll horizontal full screen for device, you need only UICollectionView, don't use UICollectionView inside UITableView – Geo Sep 26 '21 at 11:18
  • I just have a problem with vertical scroll in a table view – iron Sep 26 '21 at 11:25