我已经按照许多教程进行操作,我的网页视图中的链接仍未在Safari中打开。 我是一个菜鸟,这是我的第一个iPhone应用程序,所以我希望我只是错过了一些简单的东西。
//
// 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
答案 0 :(得分:0)
shouldStartLoadWithRequest方法是否会触发?可能是您没有在nib文件中连接委托。通常这将连接到您的视图控制器,或任何找到shouldStartLoadWithRequest方法的文件。