MikeN
MikeN

Reputation: 46287

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 then 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?

Upvotes: 1

Views: 124

Answers (1)

christo16
christo16

Reputation: 4843

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];
}

Upvotes: 2

Related Questions