iOS xcode按钮没有链接。

时间:2012-05-14 21:19:22

标签: ios xcode button

我的主故事板上有一个按钮。我很确定它是正确连接的,但是当我运行模拟器并按下按钮时,它什么也没做。按钮打开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

1 个答案:

答案 0 :(得分:1)

网址需要方法和地址,因此请尝试@“http://www.google.com”。要证明您的操作是否正确连接,请从方法中打印一条日志消息(或使用断点)。