aschuch / StatefulViewController

Placeholder views based on content, loading, error or empty states
MIT License
2.14k stars 149 forks source link

Add instructions to change backing view. #13

Open kapoorsahil opened 8 years ago

kapoorsahil commented 8 years ago

I want a subview of my controller to change loading state. Is it possible?

I added this to my controller but doesn't work

var backingView: UIView {
    return contentView
}
alinekborges commented 7 years ago

image

Try this, it worked fine for me :)

drpawelo commented 7 years ago

@alinekborges Thanks so much! here's your answer as text (and with some explanation):

  1. Your ViewController already most likely adopts StatefulViewController protocol. Make it also adopt BackingViewProvider protocol like this: open class GenericCollectionVC: UIViewController, StatefulViewController, BackingViewProvider {
  2. then in your code re-define what view should hold all the StatefulViews (emptyView, loadingView, errorView) by defining backingView variable public var backingView: UIView { return self.collectionView }
  3. Note that I set self.collectionView to be the parent view of my StatefulViews, but you can use any view there