Reputation: 11
I am working with xcode and I'm stuck in writing URL links. I want the user to fill the rest of my written URL code.
Here's the code:
- (IBAction)openURL:(id)sender { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://facebook.com/....."]]; }
The user will see this: facebook.com/write your address here...
The "facebook.com/" part is a label and the "write your address here..." a textfield that is filled in the apps settings. For example I can write "JJMLS" in settings, so the result is "facebook.com/JJMLS".
I have sat a custom/invisibile "openURL" button over the result area.
How can I tell xcode that @"http://facebook.com/(.....)" part is an area that should get the JJMLS result when the user fills it???
I will really appreciate some help!
-JJ
Upvotes: 0
Views: 105
Reputation: 11595
Try something like this:
- (IBAction)openURL:(id)sender {
if(textfield.text == nil){
UIAlertView *noTextAlert = [UIAlertView initWithTitle: @"No text entered!"
message: @"Please enter some text"
delegate: self
cancelButtonTitle: @"Ok"
otherButtonTitles: nil];
[noTextAlert show];
}
else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://facebook.com/%@", textfield.text]]];
}
}
If you have any questions about the code, just put it in the comments. Hope this helps!
Upvotes: 2