Uiwebview with modifiable URL

Discussion in 'iOS Programming' started by Appzyme, Mar 29, 2011.

  1. macrumors newbie

    Joined:
    Mar 29, 2011
    #1
    I have created an app with a uiwebview. Now I want to allow the user to be able to change the URL by using a settings like interface. Any help with a solution would be greatly appreciated. So to be clear my webview is initially programmed for www.google.com and I want the user to be able to change to www.yahoo.com or www.whatever.com.
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    How u want them to change the URL, quite important, u want an adress bar, or u want a settings screen, where they can touch something, or whatever.
    Please explain a bit more, and i might help u out there :)
     
  3. thread starter macrumors newbie

    Joined:
    Mar 29, 2011
    #3
    Thanks for the reply jnoxx! I want them to be able to press a button and then be taken to a settings screen where they can then modify the current url. Sure hope you can help.
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Modify how? By using a text field? Or by picking a choice amongst various options?
     
  5. thread starter macrumors newbie

    Joined:
    Mar 29, 2011
    #5
    Hey Dejo! My bad. By using a text field which contains the current url.
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Alright, thanks for the clarification.

    So, what exactly are you seeking help for now? Is there some specific piece to your solution that you are seeking advice on? Or what?
     
  7. thread starter macrumors newbie

    Joined:
    Mar 29, 2011
    #7
    I'm not sure how to create the settings view that contains the editable "text region" for the url to the webview and then how to connect this "text region" variable to [NSURL URLWithString:mad:"text region"]
     
  8. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #8
    Easy/most hack and slash coding like is.
    On button, load a new modal view controller, load the text from the textfield into a NSUserDefaults, and allways make the label show the current NSuserDefaults too.
    Tadaa :)
    And if they press a button, dismiss modal view, and load the view from the user defaults ;)

    But they are more cleaner ways of doing this :)
     
  9. Appzyme, Mar 30, 2011
    Last edited: Mar 30, 2011

    thread starter macrumors newbie

    Joined:
    Mar 29, 2011
    #9
    Thanks jnoxx. I'm going to try and decode your suggestion :confused: But what are the cleaner ways to do this?
     
  10. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #10
    I said, cleaner, not easier ;)

    Pop a modal screen, that should be fairly easy to figure out.
    Put in a UITextfield, add the UITextField delegate to your H file.
    on enter, or whatever, save the .text of the textfield into a string. and share that with your other view controller where u need it.
    This is the real good way.
    But most "beginning" programmers having trouble in Objective-C with sharing data between viewControllers. That's why i suggested to use the NSuserDefaults hack (just save it into the background kind off).
    and then retrieve it in ur website URL thingy. :)
    Any more questions?

    PS: this doesn't mean you have to do it this way, just inputting here :)
     
  11. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #11
    You should be aware that Apple has some strict and oddball rules regarding webviews where the user can type in the URL. They require that any app with this feature be listed for age 17+ because it's possible to view p0rn with such an app.

    I've never heard of a UI like you describe where the user can choose from among a set of URLs but if the user can type in the URL then this rule may come into effect. If instead you have a set of preset URLs that the user can choose from then maybe the rule won't apply.
     
  12. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    I wouldn't call using NSUserDefaults a hack. It is just one approach among many to data-persistence and comes with its own pros and cons. For example, one pro is that they provide an easy way to preserve values across runs of the applications and another is that they are backed up when synching with iTunes (so, you should be able to delete an application, restore from backup and the values contained in the user defaults should be restored as well).
     
  13. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #13
    Interesting, learned something new today.
    About the "hack", well. whatever, you're right x)
    I just use it for like 1 integer, but for saving a bunch, I would recommand other ways :)
     
  14. thread starter macrumors newbie

    Joined:
    Mar 29, 2011
    #14
    Thanks jnoxx and dejo! PhoneyDeveloper I'll keep that in mind for sure.
     

Share This Page