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?
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
A URL needs a method as well as an address, so try @"http://www.google.com". To prove whether your action is hooked up right, print a log message from the method (or use a breakpoint).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.