aschuch / StatefulViewController

Placeholder views based on content, loading, error or empty states

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not working on a UITableViewController

ed-mejia opened this issue Β· comments

Hi, this is a great lib, I used it over a UIViewController and works wonderfull

But then I tried to use it on a UITableViewController and it does not work at all πŸ˜“

commented

Is there any plan to support UITableViewController?

Hi, yes I've see this as well. For some reason, UITableViewController does some internal layouting that prevents any added subviews to correctly show and hide.
I do intend to support UITableViewController at some point, but I'll need to investigate a bit more. If anyone has a workaround or more info on UITableViewController internals, I am all ears. πŸ’―

Have you tried setting the layer.zPosition of the subview to a number higher than that of the UITableView on the controller? Or possibly just using `bringSubviewToFront(view:)

Well, setting the layer.zPosition was a part of the solution, but it wasn't nearly as simple as that! I've made a PR that solves this. @aschuch, let me know what you think of it!

@aschuch Hey there! Just wanted to confirm that this library is still actively maintained, since we haven't heard any reply about the fix I've proposed. It's totally fine if you're busy right now and just need some time to get to it, but I'm just confirming, because if this isn't being maintained, I'm gonna push a new Pod from my fork. Thanks! :)

Hi, yes this framework is still actively maintained. I am quite busy right now, so I am not as responsive as I should be atm. I'll definitely try to get a look at this soon. ✌️

Any progress?

commented

^

i tried many times...but not my mistake...

@aschuch Any progress so far?

Hi @bjrne I came up with some hack to make it work.

In your UITableViewController

Create a container view:

var sfViewContainer: UIView!

And then in your viewDidLoad:

// for UITableViewControllers we need to setup a special container, 
// we can't use ViewStateMachine     the same way like in UIViewControllers
        sfViewContainer = UIView(frame: tableView.bounds)
        sfViewContainer.backgroundColor = .clear
        sfViewContainer.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        tableView.addSubview(sfViewContainer)
        tableView.bringSubview(toFront: sfViewContainer)
// stateMachine is your ViewStateMachine
        stateMachine = ViewStateMachine(view: sfViewContainer)

after this initial setup you should be able to use StatefulViewController as usual.

@ed-mejia Thanks a lot! I'll try this.

I've pushed some changes to master that allow for better support of UITableViewController and UICollectionViewController (thanks @AnthonyMDev).
Please take a look and report any issues. Thanks! ✌️

@aschuch, The master version of this library seems to get UITableViewController working quite nicely. The workaround you proposed doesn't work because the stateMachine property is read-only.

We'd prefer to use an 'actual release' so could you please publish a new release so we could take our dependency on it?

In addition, I also wanted to get your thoughts on using this library, as opposed to other options as proposed by these blog posts / github + videos:

As a Swift developer, I greatly appreciate you creating this library and I've used it in a few apps. Would like to know if you have a new preference moving forward and we can point our Swift / App developer community towards that.