views:

170

answers:

2

Hello, I am making a twitter application for iPhone, I am trying to add a button which will open Safari, and take the user to their twitter homepage. I have a textfield called username, so the following code does not work, hopefully someone will be able to help me out.

-(IBAction)viewAccount {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.twitter.com/", username.text]];

}

Any help is appreciated! Thank you!

A: 

Try this

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.twitter.com/%@", username.text]]];
Vnuce
Thank you so much dude!!!
Daniel Ricany
You might want to mark this question as answered so it wouldn't show up in the unanswered list anymore :)
Vnuce
A: 

Check if your URL is correct

NSURL* twitterURL = [NSURL URLWithString:@"http://www.twitter.com/", username.text];
NSLog(@"my twitter url: %@", twitterURL);

edit: seems someone was faster than me ;)

Martin Brugger