2012-05-14 88 views
0

我的主要故事板上有一個按鈕。我很確定它是正確的連接,但是當我運行模擬器並按下按鈕時,它什麼都不做。我錯過了什麼讓按鈕打開Safari?iOS xcode按鈕沒有鏈接。

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 

回答

1

的URL需要一個方法以及一個地址,所以儘量@「http://www.google .COM」。爲了證明您的動作是否正確連接,請從方法中打印日誌消息(或使用斷點)。

+0

謝謝,加入http修復了這個問題,我很高興它是簡單的東西! –

+1

那就別忘了接受他的回答! – benuuu