Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tominated

macrumors 68000
Original poster
Jul 7, 2006
1,723
0
Queensland, Australia
What and where would i put into

Code:
- (IBAction)connectURL:(id)sender{
[urlString setStringValue:[sender stringValue]];
[[webView mainFrame] loadRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:
[sender stringValue]]]];
}

to make it automatically insert the 'http://' infort of the url if it isn't already there.

BTW: this is what happens to my url text field when enter is pressed.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Assuming sender is the NSTextField:

Code:
- (IBAction)connectURL:(id)sender
{
    NSString *url = [sender stringValue];
    if (![url hasPrefix:@"http://"])
        url = [NSString stringWithFormat:@"http://%@", url];
    [urlString setStringValue:url];
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}
 

tominated

macrumors 68000
Original poster
Jul 7, 2006
1,723
0
Queensland, Australia
Assuming sender is the NSTextField:

Code:
- (IBAction)connectURL:(id)sender
{
    NSString *url = [sender stringValue];
    if (![url hasPrefix:@"http://"])
        url = [NSString stringWithFormat:@"http://%@", url];
    [urlString setStringValue:url];
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

Awesome! thanks! w00t!
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Code:
- (IBAction)connectURL:(id)sender{
[urlString setStringValue:[sender stringValue]];
[[webView mainFrame] loadRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:
[sender stringValue]]]];
}
I see you're ignoring my advice about indenting your code and not breaking your lines into non-sensical separate lines that make your code harder to read.

Notice the difference between the way your code is written and Kainjow's. His is easy to read....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.