1

Ive gone and set up a collectionview inside another collectionview and for the most part it seems to be working ok. But there is a bit of a glitch with trying to display or edit UI elements from various parts of my code.

In cellForItemAt i can successfully display images and other UI elements in the cell using the usual format.

In didSelectItemAt it appears that the UI of the cell can not be manipulated. Take below for example. When i select a cell i want to add an activity indicator, which is pretty standard. Ive done this in other places:

AIV Defined:

let activityIndicatorView : UIActivityIndicatorView = {
    let aiv = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.white)
    aiv.color = UIColor.black
    aiv.translatesAutoresizingMaskIntoConstraints = false
    aiv.isUserInteractionEnabled = false
    aiv.startAnimating()
    return aiv
}()

Then in didSelectItem i try activate it in the cell:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

let cell: InnerCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierInner, for: indexPath) as! InnerCollectionCell

cell.contentView.addSubview(self.activityIndicatorView)
self.activityIndicatorView.centerXAnchor.constraint(equalTo: cell.contentView.centerXAnchor).isActive = true
self.activityIndicatorView.centerYAnchor.constraint(equalTo: cell.contentView.centerYAnchor).isActive = true

// bunch of attempts to try display - no luck
cell.contentView.bringSubview(toFront: self.activityIndicatorView)
self.activityIndicatorView.isHidden = false
cell.setNeedsDisplay()
cell.setNeedsLayout()
collectionView.reloadItems(at: [indexPath])

And nothing displays. If i print to the console

print(cell.contentView.subviews)

I get a bunch of stuff that is added in Interface Builder and i see the activity indicator listed as a subview:

<UIProgressView: 0x7ff280e1bf20; frame = (5 24; 40 2); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x60800003da80>>, 
<UIImageView: 0x7ff280d3b940; frame = (0 0; 15 15); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x608000234ce0>>, 
<PFImageView: 0x7ff280d3eb70; baseClass = UIImageView; frame = (0 0; 50 50); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x60800022b320>>, 
<UIActivityIndicatorView: 0x7ff280c5df10; frame = (0 0; 20 20); userInteractionEnabled = NO; layer = <CALayer: 0x600000430280>>]

So its there but I'm having real difficulty trying to get this to display.

Pippo
  • 1,439
  • 1
  • 18
  • 35
  • Why dont you add the indicator in the InnerCollectionCell nib and on didSelectItemAt indexPath just make it hide and show. – Muneeba Feb 09 '17 at 12:47
  • I haven't tried a nib file but if i add it in interface builder and create an outlet i still cant show / hide it. Ive got the progress view and image view built in that way and cant edit their display state from didselectitem – Pippo Feb 09 '17 at 20:29

0 Answers0