0
我遵循了许多教程,并且我的Web视图中的链接仍未在Safari中打开。 我是一个noob,这是我的第一个iPhone应用程序,所以我希望我只是缺少一些简单的东西。Iphone WebView链接无法在Safari中打开
//
// ViewController.m
// FirstIphoneApp
//
// Created by admin on 12/2/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "ViewController.h"
@implementation ViewController
@synthesize webView;
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://somewebsite.com/iphone.html"]]];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
这里是我的头文件
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIWebViewDelegate,UIAlertViewDelegate>{
IBOutlet UIWebView *webView;
}
@property(nonatomic, retain) IBOutlet UIWebView *webView;
@end
啊,是我设置一个断点,它似乎并没有被击中。我没有看到一个nib文件,是XCode 4.2.1中的“storyboard”文件吗?并且你能提供关于连接故事板中的委托的任何指示吗? – TreK
我能找到代表。我选择了View而不是View Controller作为Delegate。有用!谢谢 – TreK