Good day dear gurus. There is a question with which I can not give fret. Climbed a bunch of sites just did not find what I needed = (For this, do not criticize much.

I have

NSURL *url = [NSURL URLWithString:@""]; 

After "mdata", I need to enter a value instead of "% @" , the user enters the text field in the XIB into the Text Field field and when you click on the Button , this URL is loaded. Then it parses, but it does not matter ...

Help it to implement, who can write the code, who knows something like that, share the link.

---------------------------- I will continue the tendency to write working code, after a successful test

Quite simply, I made IBAction attached it to a button.

 -(IBAction)getInfo:(id)sender { NSString *urlText = [NSString stringWithFormat:@"", self.nick.text]; NSURL *url = [NSURL URLWithString:urlText]; //Конечно не забываем убирать клавиатуру, а то она за 15 тестов меня задолбала. [self.nick resignFirstResponder]; 

Indulge in! Thank you all for the help! PS do not forget to tie a button!

  • Uh ... Why do you compose a URL without replacing a piece of string? First, replace the% @ line with what you need, then make the URL from the resulting string. Because otherwise, you will need to pull the string out of the URL again, replace the piece, and pack into the new URL. - VladD
  • I imagined it to be some other kind. As in any browser, http: // is hidden when you enter the site name, the browser itself adds http: // the same thing I want to do =) I thought it would be easier so - Svyatoslav Boyko

1 answer 1

Do this:

 NSString *urlTemplate = @""; NSString *expandedUrlTemplate = [NSString stringWithFormat:urlTemplate, __here_your_string__]; NSUrl *url = [NSURL URLWithString:expandedUrlTemplate]; 
  • one
    Only better yet NSString *expandedUrlTemplate = [NSString stringWithFormat:urlTemplate ,__here_your_string__]; - aknew 8:39
  • It didn't work out = (Many error when crash removed - Svyatoslav Boyko
  • @aknew: sure, thanks! Correct the answer. - VladD
  • @ Svyatoslav: where are the mistakes, where is the crash? Here or somewhere else? - VladD
  • Crash was on the URL - Svyatoslav Boyko