UIWebView的一些总结

本文详细介绍了如何在iOS应用中使用UIWebView实现前进后退按钮的直接绑定,优化了网页加载时的视觉体验,并提供了UIWebView在执行网页导航操作时避免崩溃的方法。同时,演示了如何在网页加载时显示进度指示器,并介绍了如何发起Google搜索请求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.UIWebView的goback和goforward事件与前进后退按钮的关联
up vote 2 down vote accept

I recommend binding the forward and backward button directly to the UIWebview.

enter image description here

Automatically enable and disable like this:

- (void)webViewDidStartLoad:(UIWebView *)mwebView {
    backButton.enabled = (webView.canGoBack);
    forwardButton.enabled = (webView.canGoForward);
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    backButton.enabled = (webView.canGoBack);
    forwardButton.enabled = (webView.canGoForward);
}

2.从UIWebView通过Navigate后退的时候,APP crash了

在UIWebView销毁之前,需要停止load WebView并删除delegate,代码如下

- (void)dealloc {
    webView
.delegate = nil;
   
[webView stopLoading];
   
[webView release];
   
[super dealloc];
}

3. UIWebView Load的时候显示菊花(Wheel)
头文件加入
UIActivityIndicatorView *loadingIndicator;

ViewDidLoad中加入
loadingIndicator = [[UIActivityIndicatorView alloc] 
initWithFrame:CGRectMake(14519020,20)];
[loadingIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[loadingIndicator setHidesWhenStopped:YES];
[webView addSubview:loadingIndicator];

-(void)webViewDidStartLoad:(UIWebView *)webView 显示滚轮

[loadingIndicator startAnimating ];

-(void)webViewDidFinishLoad:(UIWebView *)webView 隐藏滚轮

[loadingIndicator stopAnimating ];

4. UIWebView发起一次google搜索

NSString *baseText = @"http://www.google.com/search?btnG=Google+Search&q=";

NSString *search = [NSString stringWithFormat:@"%@%@" , baseText, self.searchText];

NSString* escapedUrlString = [search stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:escapedUrlString]]];

 

转载:http://ihelloray.blog.163.com/blog/static/18748808620115266268876/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值