0

I have a webView in a simple application which is under a UIImageView. I intend on displaying the UIImageView until webView loads some data and fires a method in the web view delegate. Webview loads the data, delegate method is called fine. However, I am having trouble manipulating other views like the UIImageView.

Here is my code;

class ViewController: UIViewController,UIWebViewDelegate {
    //contains the imageView and activityWorkingIndicator 
    @IBOutlet weak var splash_view: UIView!
    @IBOutlet var contentWebView: UIWebView!
    //Contains the Webview and other views to be displayed after the splash his hidden
    @IBOutlet weak var splash_view_not: UIView!

    override func viewWillAppear(animated: Bool)
    {
        contentWebView?.scrollView.bounces = false;
        contentWebView?.delegate = self
        let url  = NSURL(string: "http://localhost/something/");
        let request = NSURLRequest(URL: url!);
        contentWebView?.loadRequest(request);
    }

    ....

    func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        if let scheme = request.URL?.scheme {
            if scheme == "myRequestScheme"{
                let task : String = (request.URL?.host)!;
                switch task {
                    case "systemReady":
                       print("checkpoint 1");//works fine
                       splash_view?.hidden = true;//no effect at all
                       splash_view_not?.hidden = false;//no effect at all
                       print("checkpoint 2");//works fine
                       break;
                    default:
                    break
                }
            }
        }

        return true;
    }
}

What am I missing here?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Your question has nothing to do with Objective-C or Xcode. Please don't add needless tags. Thanks, – rmaddy Nov 30 '16 at 05:10

2 Answers2

0

It looks like you are using Auto Layout. If that is the case, using .hidden has more implications than you think. If you are calling it in a method after the view has already been loaded, you need to work with constraints instead of hidden. Some people create constraint outlets and set them to active to hide things. Some people set alphas and bring subviews to front to hide things, etc.

I believe this is the preferred way: http://candycode.io/hiding-views-with-auto-layout/

And here is a stack overflow thread with A LOT of information on your best options to hide things with AutoLayout: AutoLayout with hidden UIViews?

Community
  • 1
  • 1
Kayla Galway
  • 662
  • 4
  • 7
0

You should hide or show any control in delegate method on main thread.

Use like this

DispatchQueue.main.async { 
      splash_view_not?.hidden = false
}