【问题标题】:How can I add navigation to embedded UIWebView?如何向嵌入式 UIWebView 添加导航?
【发布时间】:2012-11-24 22:13:57
【问题描述】:

我正在使用 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"];

}

【问题讨论】:

  • 一开始你尝试了什么?你看过谷歌吗?告诉我们你尝试了什么。

标签: iphone ios uiweb


【解决方案1】:

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

[[self mainWebView] goForward];

【讨论】:

  • 感谢您的回答。 DenVog,是的,但当时我尝试了一对不起作用的。我最终使用了 IB 并添加了一个带有按钮的工具栏,然后右键单击并拖动到 Web 视图。另外,如果其他人对源代码感兴趣,请参阅我上面的编辑。
猜你喜欢
  • 2019-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-30
相关资源
最近更新 更多