在我的应用程序我有UX我可以在水平和垂直方向滚动,所以我创建了CollectionView,哪个单元格包含TableView,但我有一些问题的元素约束,我把它放在UITableViewCell,这里是视频,它是怎么回事看着我的iphone http://dropmefiles.com/jgDC8,但是在故事板中,我在我的imageView上设置了约束,所以它必须在单元格中水平居中,其他单元格也在右边有一些混合 .

Screen in storyboard

这是我的代码,它是简单的UICollectionViewDataSource和Delegate方法,UITableViewDataSource和Delegate方法 .

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as! CellWithTableView
    cell.delegate = self
    cell.tableView.scrollToRow(at: numberOfSection, at:  .top, animated: false)
    print("SCROLLTOINDEXFROMCEKKFORITEM: \(numberOfSection)")
    cell.currentColumn = indexPath.row
    return cell
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    let bounds = UIScreen.main.bounds
    return CGSize(width: bounds.width + 100, height: bounds.height)
}

}

这是我的UICollectionView单元格

func numberOfSections(in tableView: UITableView) -> Int {
    return 2
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if section == 0 {
        return 1
    }
    return 99
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if indexPath.section == 0 {
        let cell = tableView.dequeueReusableCell(withIdentifier: "menu") as! MainMenuCell
        cell.imageView?.image = imageForMenu(column: currentColumn)
        return cell
    }
    let cell = tableView.dequeueReusableCell(withIdentifier: "submenu")
    return cell!
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 0.001
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 0.001
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.section == 0 {
        return UIScreen.main.bounds.height
    } else {
        return 44
    }
}

func imageForMenu(column: Int) -> UIImage {
    switch column {
    case 0:
        return UIImage(named: "Addnew")!
    case 1:
        return UIImage(named: "Playerslist")!
    default:
        return UIImage(named: "Feedback")!
    }
}

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    let firstVisibleIndexPath = tableView.indexPathsForVisibleRows![0]
    print("CURRENTINDEX: \(firstVisibleIndexPath)")
    delegate?.changeCellsOfOtherRableViews(indexPath: firstVisibleIndexPath, currentColumn: currentColumn)
    numberOfSection = firstVisibleIndexPath
}

另外我想知道,我怎么能做以下,每次我更改tableView当前顶部单元格的indexPath它会自动更改UICollectionView的其他单元格?