单元格获取其前一个单元格的索引 - Tableview 中的 Collectionview
Cell takes index of its previous cell - Collectionview inside Tableview
我想在表视图中动态添加集合视图。我做了以下代码。
集合视图的单元格class
class NewsFeedCollectionViewCell : UICollectionViewCell{
@IBOutlet weak var imageViewSlider: UIImageView!
}
比在 Tableview cellforrow at indexpath
中分配 collectionview
cell.collectionViewNewsFeed.tag = indexPath.row
cell.collectionViewNewsFeed.reloadData()
比添加以下 collectionview 代表
// MARK: - Collection view Delegates / Datasources
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (mutableArrayNewsFeed[collectionView.tag]["images"] as! NSArray).count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("NewsFeedCollectionViewCell", forIndexPath: indexPath) as! NewsFeedCollectionViewCell
print("tag : \(collectionView.tag) , Row : \(indexPath.row)")
let img = (mutableArrayNewsFeed[collectionView.tag]["images"] as! NSArray)[indexPath.row] as? String ?? "imgLoginScreenLogo"
cell.imageViewSlider.image = UIImage(named: img)
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("Collection View Row : \(indexPath.row)")
}
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{
return collectionView.frame.size
}
其调整正确,但索引在我滚动集合视图时发生变化。例如,我将 collectionview 滚动到 3 个单元格,然后转到 tableview 的第 4 个索引,然后它还将 collectionview 的第 4 个索引的索引设置为第 3。
只是想在 Table 视图中添加包含多个图像的集合视图。我已经添加了,但是在将集合视图滚动到表格视图第一个单元格的第三个图像后,我移动到 Table 视图的第四个单元格,集合视图也自动滚动到第四个单元格。
需要摆脱这个。
索引路径有问题,我通过将索引路径保存在数组中得到了解决方案。
参考关注link
https://github.com/ashfurrow/Collection-View-in-a-Table-View-Cell
我想在表视图中动态添加集合视图。我做了以下代码。
集合视图的单元格class
class NewsFeedCollectionViewCell : UICollectionViewCell{
@IBOutlet weak var imageViewSlider: UIImageView!
}
比在 Tableview cellforrow at indexpath
中分配 collectionviewcell.collectionViewNewsFeed.tag = indexPath.row
cell.collectionViewNewsFeed.reloadData()
比添加以下 collectionview 代表
// MARK: - Collection view Delegates / Datasources
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (mutableArrayNewsFeed[collectionView.tag]["images"] as! NSArray).count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("NewsFeedCollectionViewCell", forIndexPath: indexPath) as! NewsFeedCollectionViewCell
print("tag : \(collectionView.tag) , Row : \(indexPath.row)")
let img = (mutableArrayNewsFeed[collectionView.tag]["images"] as! NSArray)[indexPath.row] as? String ?? "imgLoginScreenLogo"
cell.imageViewSlider.image = UIImage(named: img)
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("Collection View Row : \(indexPath.row)")
}
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{
return collectionView.frame.size
}
其调整正确,但索引在我滚动集合视图时发生变化。例如,我将 collectionview 滚动到 3 个单元格,然后转到 tableview 的第 4 个索引,然后它还将 collectionview 的第 4 个索引的索引设置为第 3。
只是想在 Table 视图中添加包含多个图像的集合视图。我已经添加了,但是在将集合视图滚动到表格视图第一个单元格的第三个图像后,我移动到 Table 视图的第四个单元格,集合视图也自动滚动到第四个单元格。
需要摆脱这个。
索引路径有问题,我通过将索引路径保存在数组中得到了解决方案。
参考关注link https://github.com/ashfurrow/Collection-View-in-a-Table-View-Cell