WebView - change scalePagesToFit for certain URL?

Discussion in 'iOS Programming' started by tomgoo, Jun 30, 2012.

  1. tomgoo, Jun 30, 2012
    Last edited by a moderator: Jun 30, 2012

    tomgoo macrumors newbie

    Joined:
    Jun 30, 2012
    #1
    Hi guys, I've got this code here for a particular URL which I don't want to scale to fit on my webview, but I want all other pages to have the scale to fit function. The problem is, it doesn't do anything. I've tried switching round the scalepagestofit code snippets and it will work the other way round?

    any help is appreciated!

    Code:
    if(currentURL==@"http://www.myurl.co.uk/search1.php") {
         
            webView.scalesPageToFit=FALSE;
            
      
            
        } else {
            
            webView.scalesPageToFit=TRUE;
        }
    This code is in my viewDidLoad, webView is a weak property? That's about all the details I think.

    Thanks,

    Tom
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Using the == operator is not the proper way to compare strings.
     
  3. tomgoo, Jun 30, 2012
    Last edited by a moderator: Jun 30, 2012

    tomgoo thread starter macrumors newbie

    Joined:
    Jun 30, 2012
    #3
    Thanks, I've changed it to this now: (with extra parenthesis I think is right):


    Code:
    NSString *currentURL = webView.request.URL.absoluteString;
        
        if((currentURL=@"http://www.myurl.co.uk/search1.php")) {
         
            webView.scalesPageToFit=FALSE;
            
      
            
        } else {
            
            webView.scalesPageToFit=TRUE;
        }

    But it's still not working for some reason?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    You're now attempting to use the = assignment operator. That definitely won't work! Look at the documentation for the NSString class. See if there's an instance method that might tell you if your URL is equal to a string.
     
  5. tomgoo thread starter macrumors newbie

    Joined:
    Jun 30, 2012
    #5
    I've found this:

    stringWithContentsOfURL:encoding:error:

    but I don't think this instance method will work with it?
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Keep looking. Remember, you are looking for a method that tells you if your URL string instance "is equal to a string".
     

Share This Page