1

我使用 UIWebView 从我的 iPhone 应用程序中访问移动网站。我需要帮助添加前进和后退导航按钮。我对此真的很陌生,所以如果有人可以提供一些好的细节,我将非常感谢您的帮助。

这是我所拥有的:

UIWebView *webView1 = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 480, 251)];
[contentView addSubview:webView1];
webView1.alpha = 1.0;
webView1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[webView1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.logsitall.com/m"]]];
webView1.scalesPageToFit = YES;
[webView1 release];


contentView.frame = self.view.bounds;
[self.view addSubview:contentView];
[contentView release];
}

- (void)viewDidUnload {
    [self setWebView:nil];
    [super viewDidUnload];
}



- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:animated];
}


@end

最终代码:

//header
@interface MywebsiteViewController : UIViewController <UIWebViewDelegate>
{
    IBOutlet UIWebView *aWebView;
}

@property (nonatomic, retain) UIWebView *aWebView;


@end

//implementation

- (void)viewWillAppear:(BOOL)animated {
    self.aWebView.delegate = self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];

    NSURL *myURL = [NSURL URLWithString:@"http://www.WebSiteToLoad.com"];
    NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];

    [aWebView loadRequest:myRequest];

}


#pragma mark UIWebViewDelegate

- (void)webViewDidStartLoad:(UIWebView *)webView{
    //show indicator while loading website
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    //turn off indicator and display the name of the website in the navBar
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];

}
4

1 回答 1

2

有很多关于UIWebView的教程……等着……万维网!也就是说,我记得,它就像在 WebView 上调用 goForward 或 goBack 一样简单:

[[self mainWebView] goForward];
于 2012-12-06T20:44:17.603 回答