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

guyddor

macrumors member
Original poster
Jan 7, 2009
32
0
Who can explain me how to use it?

I try to build an app that the user will enter one word in UITextField and click a button and a safari window will open with the following address:


http://www.[the word in UITextField].com
 
the documentation knows best... check out "Combining Strings" under tasks of NSString Class Reference.

i think hes more going to want StringWithFormat

but i think hes actually looking for the call to open a webpage in safari
think its:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mad:"http://ww.google.com/"]];

something like that
 
silly me. i suppose stringWithFormat would be easier :eek:

Code:
- (IBAction)gotoURLAction
	{
	NSString *preURL = @"http://www.";
	NSString *postURL = @".com";
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", preURL, textField.text, postURL]]];
	}
 
silly me. i suppose stringWithFormat would be easier :eek:

Code:
- (IBAction)gotoURLAction
	{
	NSString *preURL = @"http://www.";
	NSString *postURL = @".com";
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", preURL, textField.text, postURL]]];
	}

Or

Code:
- (IBAction)gotoURLAction
	{
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"www.%@.com", textField.text]]];
	}

Which is even easier :)
 
Or

Code:
- (IBAction)gotoURLAction
	{
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"www.%@.com", textField.text]]];
	}

Which is even easier :)

Thanks a lot!!!
And if I want more then one word?
 
Simple:

Code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"www.%@%@.com", textField.text, textField2.text]]];
 
Simple:

Code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"www.%@%@.com", textField.text, textField2.text]]];

Thanks you but still I can't write more then one word
 
What do you mean by "more than one word"? Are you talking about taking "word1 word2" and using that in a URL, like "www.word1word2.com"?
 
What do you mean by "more than one word"? Are you talking about taking "word1 word2" and using that in a URL, like "www.word1word2.com"?

No, I mean that I will be able to write in the UITextField:

MacBook Pro

Then I will click a button and it will open the url:

http://www.MacBook Pro.com

(I know that there no urls with earnings but I want to know how to use it
 
No, I mean that I will be able to write in the UITextField:

MacBook Pro

Then I will click a button and it will open the url:

http://www.MacBook Pro.com

(I know that there no urls with earnings but I want to know how to use it

It should open the exact text in the field, but I don't know what kind of domains have spaces in them.
 
I don't know about domains having spaces in them but files in a URL can have a space in them. Oddly enough the URL keyboard doesn't have a space character in it. In general when building a URL that might have some special characters in it you use something like

Code:
NSURL* url = [[NSURL alloc] initWithString:[inURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

In which case the space and any other special characters will be % encoded.
 
As has been said, domains are not allowed to have spaces in them. So, given that, how do you want to handle "MacBook Pro" now?

I want to know for future use, I know that it impossible to use urls with spaces.
I still want to know:

The user should enter a word or more in the UITextField, then the user will click a UIButton and it will open the url with the words that he wrote in the UITextField, for example:

http://www.macrumors forum.com
 
You just have to remove the spaces from the text field. Simply split the field on the spaces, and then recombine the array of split text. Therefore all spaces will be gone.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.