Ios 如何在swift 3中的tableview单元格内添加具有自定义视图的collectionView?
我需要在tableview单元格中的视图中添加集合视图。 下图描述的正是我所需要的Ios 如何在swift 3中的tableview单元格内添加具有自定义视图的collectionView?,ios,swift,uitableview,swift3,uicollectionview,Ios,Swift,Uitableview,Swift3,Uicollectionview,我需要在tableview单元格中的视图中添加集合视图。 下图描述的正是我所需要的 tableView - tableViewCell - contentView -monthView -detailedView -collectionView - collection Cell -detailedImageView 我在detailedView(tableview单元格第二视图)中添加了collect
tableView
- tableViewCell
- contentView
-monthView
-detailedView
-collectionView
- collection Cell
-detailedImageView
我在detailedView(tableview单元格第二视图)中添加了collectionview。但是我不知道是否需要创建collectionView cell.swift文件,以及如何完成整个过程???首先,您需要创建collectionView cell文件。下面是一些示例代码,首先为CollectionView创建contentOffset数组
var contentOffsets = [Int : CGFloat]()
然后可以为每行collectionView设置标记,以识别调用了哪个collectionView委托方法
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: booksListCellId) as! BooksListCell
cell.collectionView.tag = indexPath.row
return cell
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let tableCell = cell as! BooksListCell
tableCell.collectionView.dataSource = self
tableCell.collectionView.delegate = self
tableCell.collectionView.reloadData()
if let offset = contentOffsets[tableCell.collectionView.tag] {
tableCell.collectionView.setContentOffset(CGPoint(x: offset, y: 0), animated: false)
}
}
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let tableCell = cell as! BooksListCell
contentOffsets[tableCell.collectionView.tag] = tableCell.collectionView.contentOffset.x
}
并在包含tableView的ViewController中实现collectionView数据源和委托方法
这可能对您有帮助。
您可以将表单元中的CopeVIEW视为正常的CopyVIEW视图!这取决于您是否需要创建自定义collectionviewcell!我更喜欢创建collectionview单元格。@SaurabhPrajapati您能提供一个与此相关的链接或描述吗。因为我是iOS新手。这个链接可以帮助你:@Pipiks谢谢