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.