0

メインストーリーボードにボタンが1つあります。正しくリンクされていることは確かですが、シミュレーターを実行してボタンを押すと、何も起こりません。Safariを開くためのボタンを取得するために何が欠けていますか?

Viewcontroller.h

#import <UIKit/UIKit.h>

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

@end

Viewcontroller.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 に答える