Question

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!

Was it helpful?

Solution

Try this

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.twitter.com/%@", username.text]]];

OTHER TIPS

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 ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top