开发者

On Iphone, how do I implement a button that will open up a website?

开发者 https://www.devze.com 2022-12-23 17:21 出处:网络
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

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

精彩评论

暂无评论...
验证码 换一张
取 消