قالب وردپرس درنا توس
Home / IOS Development / IOS – UICollectionView reuse in UITableViewCell

IOS – UICollectionView reuse in UITableViewCell



I know that this question is already asking many times, but not by the solution will work.

I have collection view in undoubted cell and I create a cell with table view and collection view in the storyboard, and my problem is I assume roll cell 1 collection view then cell 4 collection is automatically scroll to that location as well. How can I cope with this situation ..

Be aware right now I'm making a static screen layout

My code

  // MARK:
// MARK: table view delegate method

func numberOfSectionsInTableView (tableView: UITableView) -> Int {
return 1
}
func tableView (tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

if Appconstant.isIpad ()
{
return 21
5.0 } return 185.0 } func tableView (table view: UITableView, numberOfRowsInSection section: Int) -> Int { return 6 } func tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { leave strCell = "WorkoutCell" // + "(indexPath.row)" la cell = tableView.dequeueReusableCellWithIdentifier (strCell) as? workout Cell // if cell == nil // { // cell = work //} return the cell! } func tableView (tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { let cell2 = cell like! workout Cell cell2.collecionWorkout.reloadData () } // BRAND: // MARK: collectionview delegate and data source // 1 func shouldInvalidateLayoutForBoundsChange (newBounds: CGRect) -> Bool { return true } func numberOfSectionsInCollectionView (collectionView: UICollectionView) -> Int { return 1 } // 2 func collectionView (collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 10 } func collectionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { return UIEdgeInsetsMake (0.0, 10.0, 0.0, 10.0) } func collectionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: NSIndexPath) -> CGSize { // Adjust cell size for orientation if Appconstant.isIpad () { return CGSize (width: 160, height: 150) } return CGSize (width: 140.0, height: 130.0) } // 3 func collectionView (collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { leave cell = collectionView.dequeueReusableCellWithReuseIdentifier ("WorkoutCollectionCell", forIndexPath: indexPath) // Configure the cell return cell }

avableview cell code

  class WorkoutCell: UITableViewCell {

@IBOutlet weak was collectionWorkout: UICollectionView!
var flowLayout: UICollectionViewFlowLayout!
override func awakeFromNib () {
super.awakeFromNib ()
self.flowLayout = UICollectionViewFlowLayout ()
if Appconstant.isIpad ()
{
self.flowLayout.itemSize = CGSize (width: 160, height: 150)
}
else
{
self.flowLayout.itemSize = CGSize (width: 140, height: 130)
}
self.flowLayout.scrollDirection =. Horizontal
self.flowLayout.minimumInteritemSpacing = 10.0
flowLayout.sectionInset = UIEdgeSetsMake (0.0, 10.0, 0.0, 10.0);
collecionWorkout.collectionViewLayout = flowLayout

// Initialization code
}

override func setSelected (selected: Bool, animated: Bool) {
super.setSelected (selected, animated: animated)

// Configure the display for the selected mode
}

}

Cell 1 as I roll

 Enter image description here

cell 4 as automatic scroll

 enter image description here


Source link