我使用以下代码进行Webview导航。
以下代码适用于某些URL,但它不起作用的某些URL ..我不知道我的错误在我的代码中...
·H
#import <UIKit/UIKit.h>
@interface WebviewViewController : UIViewController <UIWebViewDelegate>
{
IBOutlet UIWebView * webview;
IBOutlet UIToolbar * tBar;
IBOutlet UIBarButtonItem * backbtn;
IBOutlet UIBarButtonItem * forwardbtn;
}
@property (nonatomic, retain) IBOutlet UIWebView * webview;
@property (nonatomic, retain) IBOutlet UIBarButtonItem * backbtn;
@property (nonatomic, retain) IBOutlet UIBarButtonItem * forwardbtn;
@property (nonatomic, retain) UIToolbar * tBar;
- (IBAction)goBackbttn:(id)sender;
- (IBAction)goForwardbttn:(id)sender;
@end
的.m
#import "WebviewViewController.h"
@implementation WebviewViewController
@synthesize webview;
@synthesize tBar, backbtn, forwardbtn;
- (void)viewDidLoad {
[super viewDidLoad];
[backbtn setEnabled : FALSE];
[forwardbtn setEnabled : FALSE];
NSString * urlAddress = @ "http://www.exampl.com";
NSURL * url = [NSURL URLWithString:urlAddress];
NSURLRequest * requestObj = [NSURLRequest requestWithURL:url];
webview.scalesPageToFit = YES;
webview.autoresizesSubviews = YES;
[webview loadRequest : requestObj];
}
- (IBAction)goBackbttn:(id)sender
{
[forwardbtn setEnabled : TRUE];
}
- (IBAction)goForwardbttn:(id)sender {
[webview goForward];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[backbtn setEnabled :[webView canGoBack]];
[forwardbtn setEnabled :[webView canGoForward]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
@end
答案 0 :(得分:2)
不应该这个
- (IBAction)goBackbttn:(id)sender
{
[forwardbtn setEnabled : TRUE];
}
是这样的:
- (IBAction)goBackbttn:(id)sender
{
[webview goBack];
}