Fogh/AFWebViewController

Allow AFWebViewController to be loaded via Storyboard

stuartjmoore opened this issue · 4 comments

Because of the initialization methods, AFWebViewController cannot be loaded from a Storyboard. Setting the NSURL after the fact would allow this.

Fogh commented

I guess that overwriting initWithCoder would solve that? Or if you have found a solution feel free to submit a pull request 😃

No need for initWithCoder; you'll have to expose and allow the NSURL to be set after initialization. Nothing too crazy, but it's a bit of a re-architecture that touches everything (my attempt knocked the networkActivityIndicatorVisible out of sync).

Honestly the difficult part is on the consuming app. You can't set the rootViewController after init, so the storyboard has to be AFModalWebViewControllerAFWebViewController. Then call:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "openWebModal" {
            let webViewController = segue.destinationViewController as AFModalWebViewController
            webViewController.url = NSURL(string: "http://www.google.com")
        }
    }
Fogh commented

I see. But is storyboard support really necessary? It is really easy to just present the view from the code. I normally use storyboard, but I haven't had a need for it to work with storyboards.

It would be a nice to have, especially if you layout your paths visually via Storyboards and set data in prepareForSegue:. Not a blocker by any means; just nit-picky.

Also, initWithURL: methods tend to be convenience for init + setURL:.