On Iphone, how do I implement a button that will open up a website?
From my Objective C iPhone app, I want a user to click on a "Register" for account button and th开发者_运维技巧en open up a registration page on my website. What is the code on the iPhone to open up a website in response to a user action?
Create a UIButton and assign the action to a method like this:
- (IBAction)register:(id)sender {
//you'll want to subclass UIViewController
SomeViewController *webViewController = [[SomeViewController alloc]init];
[self presentModalViewController:webViewController animated:YES];
[webViewController release];
}
Your SomeViewController will have a webview that load's your register page. Then in your "SomeViewController"'s viewDidLoad, do something like this:
- (void)viewDidLoad
{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mysite.com/register"]];
//this is a webview that you either created in -loadView or IB
[self.webView loadRequest:request];
}
精彩评论