0

I have a two-days-brain-breaking-question to all of you:

I integrated a menu in my application by using a UICollectionView (one line, horizontal scrolling, fixed number of 9 items). Every cell has an own tag and uses an own prototype cell with own identifier. During the cellForItemAtIndexPath I assign a prototype cell to every cell (the prototype cell contains the specific UIButton in the storyboard). If you click a cell (respective the UIButton) a popover should open (this is working quite well, because the popover is anchored to the collection view not to the cell - otherwise Xcode will give an error, because of an outlet bind to repeating content.). Now to the questions:

  1. Dependently from the chosen value in the popover, the name (titleLable.text) of the button should change. I think, an IBOutlet is needed, but not usable, because of the possible (but not happened) multiple (re)use of the cell.

  2. Some other action in the APP could happened randomly, that changes the label of the button. Therefore an IBOutlet is needed too, I think.

I tried to give the prototypes a specific tag, but this (in my opinion) could not be used, because I cannot assign the tags to an UIButton, during loading, because not all of the cells are visible and therefore not reachable in viedDidAppear...

Any help is appreciated. This is a new try for an old problem and the collectionView till yesterday looked quite promising. Any ideas to help? Thanks a lot. I canĀ“t give code, because 90% of the work are done in IB.

Duckjd
  • 65
  • 1
  • 4

1 Answers1

0

you can use NSNotificationCenter to send message from your UIPopoverController to a UICollectionViewCell.

Send and receive messages through NSNotificationCenter in Objective-C?

Just subclass UICollectionViewCell to MyCollectionViewCell and use your subclass in your UICollectionView.

At the -(void)initWithFrame:(CGRect)frame method of MyCollectionViewCell you should subscribe as an observer to NSNotificationCenter, and unsubscribe in dealloc.

Than all your cells may receive notification and react to it. This is not an optimal way of receiving callbacks, but maybe the simplest.

Community
  • 1
  • 1
Alexander Tkachenko
  • 3,182
  • 1
  • 31
  • 46