0

我的主故事板上有一个按钮。我很确定它已正确链接,但是当我运行模拟器并按下按钮时,它什么也没做。我缺少什么来获得打开 Safari 的按钮?

视图控制器.h

#import <UIKit/UIKit.h>

@interface testViewController : UIViewController
- (IBAction)openSafari:(id)sender;

@end

视图控制器.m

#import "testViewController.h"

@interface testViewController ()

@end

@implementation testViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)openSafari:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.google.com"]];
}
@end
4

1 回答 1

1

URL 需要方法和地址,所以试试@"http://www.google.com"。要证明您的操作是否正确连接,请从该方法打印一条日志消息(或使用断点)。

于 2012-05-14T21:22:41.167 回答