in Education by
I have a UICollection that shows a padlock on cells that locked to users who aren't logged in. The user can view the collection and then login in a modal. When the modal dismisses, I am trying to reload the cells of the table and the nested collection to remove the padlocks from the cells. The visible cells are not refreshing to remove the padlock. When the collection is scrolled, the cells offscreen are correct and show with padlock. I am calling reloaddata() on both the tableview and each nested collectionview. The code I have is separated to: UIViewController override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("SectionWorkouts", forIndexPath: indexPath) as! SectionTableViewCell cell.delegate = self // Return the workouts count from the section let intIndex = indexPath.row let index = workoutSections.startIndex.advancedBy(intIndex) let currentWorkoutSectionKey = workoutSections.keys[index] if let currentWorkoutSection = workoutSections[currentWorkoutSectionKey] { cell.workoutsCollection.dataSource = sectionWorkoutsCell cell.workoutsCollection.delegate = sectionWorkoutsCell cell.updateCellWithWorkouts(currentWorkoutSectionKey, workouts: currentWorkoutSection) } } return cell } UITableViewCell class SectionTableViewCell: UITableViewCell,UICollectionViewDelegate, UICollectionViewDataSource { var workouts = [Workout]() var delegate: WorkoutCellDelegate? @IBOutlet weak var sectionTitle: UILabel! @IBOutlet weak var workoutsCollection: UICollectionView! func updateCellWithWorkouts(title: String, workouts: [Workout]){ self.sectionTitle.text = title self.workouts = workouts dispatch_async(dispatch_get_main_queue(),{ self.workoutsCollection.reloadData() }) } func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { return 1 } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("SectionWorkoutCell", forIndexPath: indexPath) as! SectionCollectionViewCell let row = indexPath.row let workout = workouts[row] cell.configCell(workout) return cell } func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return workouts.count } func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { let row = indexPath.row let feature = workouts[row] if let delegate = self.delegate{ delegate.didSelectWorkoutCell(feature) } } } UICollectionViewCell class SectionCollectionViewCell: UICollectionViewCell { @IBOutlet weak var imageContainer: UIView! @IBOutlet weak var image: UIImageView! @IBOutlet weak var tintOverlay: UIView! @IBOutlet weak var padlock: UIImageView! @IBOutlet weak var workoutTitle: UILabel! @IBOutlet weak var duration: UILabel! var locked = true required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } func configCell(workout: Workout){ self.workoutTitle.text = workout.name if workout.type == "Free" || AccountManager.userIsLoggedInMember() { self.setToUnLocked() }else{ self.setToLocked() } self.layoutIfNeeded() } func setToUnLocked(){ locked = false tintOverlay.alpha = 0 padlock.alpha = 0 } func setToLocked(){ locked = true tintOverlay.alpha = 0.6 padlock.alpha = 1 } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You should probably move the call to configure the cell to the willDisplayCell: method instead. You can remove it from the cellForItemAtIndexPath method. This is the correct time to configure any visual aspects of the cell to be displayed. func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let row = indexPath.row let workout = workouts[row] cell.configCell(workout) return cell }

Related questions

0 votes
    I am creating an UITableView using auto layout and prototype cells. I would like it to act more like ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I have a UITableView inside a UITableViewCell (Scrolling is disabled for the nested UITableView) Everything works ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I have a UITableView inside a UITableViewCell (Scrolling is disabled for the nested UITableView) Everything works ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 26, 2022 in Education by JackTerrance
0 votes
    I have a UITableView inside a UITableViewCell (Scrolling is disabled for the nested UITableView) Everything works ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I'm basically trying to build a game board. For simplicity's sake, imagine a Jeopardy! board. I'd ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I've set up a simple app to run in a page tab. After authorizing the use of the app, just for ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 16, 2022 in Education by JackTerrance
0 votes
    I'm trying to overlay 2 ImageViews, one with the background and one with an animated (using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I'm trying to overlay 2 ImageViews, one with the background and one with an animated (using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I've custom UICollectionViewCell that contains UILabel and UIImage. I want to set the cell in circular ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    I've custom UICollectionViewCell that contains UILabel and UIImage. I want to set the cell in circular ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I've custom UICollectionViewCell that contains UILabel and UIImage. I want to set the cell in circular ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I've custom UICollectionViewCell that contains UILabel and UIImage. I want to set the cell in circular ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    Hello I am using native UITableViewCell in my UITableView. When I set the image of the cell it looks ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    I have a UITextField inside of a UITableView cell. When I rotate the device, the textfield is still the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    All the Visible Layers in a Restricted Boltzmannn Machine are connected to each other. A. True B. False...
asked Dec 26, 2022 in Technology by JackTerrance
...