sajid
sajid

Reputation: 39

webview with configurable URL

I am new to objective c programming and working with cocoa application.

Here is my static URL webview based application.

AppDelegate.h contains

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet WebView *webview;

@end

And my AppDelegate.m contains

@implementation AppDelegate

@synthesize webview;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

    NSString *urlString = @"http://www.google.com";
    [[webview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];

}

@end

It is working fine with this specified URL.

I am trying to find out solution which make me able to configure URL. e.g save URL from separate window and load my webview with new specified URL by hitting on Save button.

Thanks in Advance

Upvotes: 0

Views: 1081

Answers (2)

SDW
SDW

Reputation: 1910

It is a lot of code to write here how to do this.

At first look at this tutorial: It will give you a specified explanation how to make a good webView: http://www.youtube.com/watch?v=hoynCQLF2H0

After that you need to have 2 views. How to do this: http://www.youtube.com/watch?v=AL13RmE18ek

Then you need to make the outlets for the UITextField and UIButton and you need to make an IBAction for the button.

After that you can use NSUserDefaults to save data and retrieve it in another view: http://www.youtube.com/watch?v=I0d1E3S-PKE

As you can see, everything that you want to know is on Youtube. Look at some great tutors like: Dani Arnaout, GeekyLemonDevelopment or TheNewBoston.

Upvotes: 1

Eli Ganem
Eli Ganem

Reputation: 1479

Create a UITextField and a UIButton. Upon a button click, load the url that was inserted into the text field. For example, lets assume your text field is called _tf and your webview is called _wv:

- (IBAction)btnClicked
{
    [_wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_tf.text]]];
}

Of course you need to validate that the entered text is actually a valid URL.

Upvotes: 3

Related Questions