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
Hi,

I want to develop an app that will take the value from UITextField and use it
in a url like that:

http://www. the value from UITextField .com/

How do I do that?
 
This should work.

Code:
NSString urlString = [NSString stringWithFormat:"http://www.%@.com/", myUITextBox.text];
 
This should work.

Code:
NSString [B][COLOR="Red"]*[/COLOR][/B]urlString = [NSString stringWithFormat:"http://www.%@.com/", myUITextBox.text];

I'll second this approach (with the minor correction I added :p). +stringWithFormat is good because it gives you an autoreleased string.
 
Thanks! but when I put the code...

The button get stuck

What to do?
 
I don't get warnings but...

Look at the attachment file
 

Attachments

  • Picture 1.png
    Picture 1.png
    169.9 KB · Views: 66
Your program appears to be crashing. Check the stack trace. I've only seen buttons get stuck like that on a crash.
 
I don't get any warnings

What to do?

Edit:

I got 2 warnings:

-passing argument 1 of 'stringWithFormat': from incompatible pointer type

-unused variable 'urlString'
 
Here the MainView.m file code

#import "MainView.h"

@implementation MainView
- (IBAction)searchGoogle {

NSString *urlString = [NSString stringWithFormat:"http://www.%@.com/", userTextField.text];

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}

@end

What to do?

This is the only code that I have in my project
 
What to do?
Two things.
1) You need to prefix your string with the @ character for Objective-C to treat it as a constant NSString object.
Code:
NSString *urlString = [NSString stringWithFormat:[COLOR="Red"]@[/COLOR]"http://www.%@.com/", userTextField.text];
2) Use [ code ] tags rather than quotes.
 
Now I get the warning:

warning: unused variable 'urlString'

What should I do?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.