Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8761713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:21:17+00:00 2026-06-13T15:21:17+00:00

Background: I have a UICollectionViewController that shows items in one of two modes, which

  • 0

Background:

I have a UICollectionViewController that shows items in one of two modes, which the user can toggle between. Each mode uses a different class of UICollectionViewCell. Let’s call these modes “list view” and “grid view”.

When I switch modes, I call .reloadData on the UICollectionView, which redraws the collection view using the correct cell classes. Everything works fine here.

Now: Inside the UICollectionViewCell subclass for one type of cells, I want to be notified when the collection view that contains it switches modes. Visually, a cell which was on-screen vanishes; the collection view is drawn fully with the other type of cell. When switching back, the cell is re-displayed.

Question:

How can I be notified when a UICollectionViewCell is “removed” (i.e., no longer shown; I’m not sure what’s happening under the hood yet) from its parent collection view?

Notes:

  • prepareForReuse is not called on the cell when the collection view’s updateData causes the cell to no longer be included.
  • willTransitionFromLayout:toLayout: (an empty layout?) is not called.
  • Overriding didMoveToSuperview is of no help; it is not called.
  • Observing .hidden or .alpha on the cell does not work.
  • The cell’s dealloc is not called; it sticks around in the reuse queue.

Something in the cell must be changing that I can observe or hook into, what is it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:21:18+00:00Added an answer on June 13, 2026 at 3:21 pm

    Update: UICollectionViewDelegate has this method, which from the documentation seems like it does what I am asking:

    • collectionView:didEndDisplayingCell:forItemAtIndexPath:

    Original answer:

    I got this working as desired by having the UICollectionViewController manually notify visible cells of impending doom with this method when I’m about to toggle and call reloadData:

    - (void)notifyCellsWillBeHidden {
        for (UICollectionViewCell *cell in self.collectionView.visibleCells) {
            if ([cell respondsToSelector:@selector(willBeRemovedFromCollectionView)]) {
                [cell performSelector:@selector(willBeRemovedFromCollectionView)];
            }        
        }
    }
    

    These cells can then do what they need to do if they implement the above method.

    Calling prepareForReuse may not a good idea because it will be called again before the cells are re-displayed, if this is a problem.

    I’m still curious whether there is a way for a cell to receive notification that it is going to be made non-visible without an explicit call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have two lists, the first is items which contains around 250 tuples,
Background : I have a few different threads which each need to write to
Background I have a dimension table that has a single record for each day.
Let's look at this picture: The left arrow shows that the button background have
Background: I have a database table which is for received_msgs The table has two
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.
Background have a custom UITableCellView in which I'm using a custom UITextField that I've
BACKGROUND: I have a set of Posts that can be voted on. I'd like
Background I have a function that takes a config object as an argument. Within
Background: I have a WebPart that makes use of the SPCalendarView control and in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.