1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Uiwebview with modifiable URL

Discussion in 'iPhone/iPad Programming' started by Appzyme, Mar 29, 2011.

  1. macrumors newbie

    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


    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. macrumors newbie

    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


    Staff Member

    Modify how? By using a text field? Or by picking a choice amongst various options?
  5. macrumors newbie

    Hey Dejo! My bad. By using a text field which contains the current url.
  6. Moderator


    Staff Member

    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. macrumors newbie

    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


    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

    macrumors newbie

    Thanks jnoxx. I'm going to try and decode your suggestion :confused: But what are the cleaner ways to do this?
  10. macrumors 65816


    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


    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


    Staff Member

    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


    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. macrumors newbie

    Thanks jnoxx and dejo! PhoneyDeveloper I'll keep that in mind for sure.

Share This Page