简体   繁体   English

iOS xcode按钮未链接。

[英]iOS xcode Button isn't linking.

I have a one button on my main storyboard. 我的主故事板上有一个按钮。 I'm pretty sure it's linked up correctly but when I run the simulator and hit the button, it does nothing. 我很确定它已正确链接,但是当我运行模拟器并按下按钮时,它什么也没做。 What am I missing to get the button to open Safari? 我不知道该怎么打开Safari的按钮?

Viewcontroller.h Viewcontroller.h

#import <UIKit/UIKit.h>

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

@end

Viewcontroller.m 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

A URL needs a method as well as an address, so try @"http://www.google.com". URL需要方法和地址,因此请尝试@“ http://www.google.com”。 To prove whether your action is hooked up right, print a log message from the method (or use a breakpoint). 为了证明您的操作是否正确,请从该方法中打印一条日志消息(或使用断点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM