PDA

View Full Version : Uiwebview with modifiable URL




Appzyme
Mar 29, 2011, 09:56 PM
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.



jnoxx
Mar 30, 2011, 02:59 AM
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 :)

Appzyme
Mar 30, 2011, 09:00 AM
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 :)

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.

dejo
Mar 30, 2011, 09:55 AM
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.
Modify how? By using a text field? Or by picking a choice amongst various options?

Appzyme
Mar 30, 2011, 09:59 AM
Modify how? By using a text field? Or by picking a choice amongst various options?

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

dejo
Mar 30, 2011, 10:04 AM
By using a text field which contains the current url.
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?

Appzyme
Mar 30, 2011, 10:18 AM
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?

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:@"text region"]

jnoxx
Mar 30, 2011, 10:28 AM
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 :)

Appzyme
Mar 30, 2011, 10:35 AM
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 :)

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

jnoxx
Mar 31, 2011, 03:17 AM
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 :)

PhoneyDeveloper
Mar 31, 2011, 07:27 AM
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.

dejo
Mar 31, 2011, 09:27 AM
That's why i suggested to use the NSuserDefaults hack

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).

jnoxx
Apr 1, 2011, 02:09 AM
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).

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 :)

Appzyme
Apr 4, 2011, 01:49 PM
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 :)

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