ios – iPad中的UIWebView后退按钮实现问题

ios – iPad中的UIWebView后退按钮实现问题,第1张

概述我已经使用UIWebView在我的应用程序中实现了一个浏览器,默认情况下我在浏览器中加载了google页面. 当我在google页面中搜索某些内容时,会调用UIWebViewDelegate的webView:shouldStartLoadWithRequest:navigationType:方法. 问题是,当我点击此搜索页面上的后退按钮时,没有代表被调用,所以我在禁用后退按钮时出现问题. 此问题仅 我已经使用UIWebVIEw在我的应用程序中实现了一个浏览器,默认情况下我在浏览器中加载了Google页面.

当我在Google页面中搜索某些内容时,会调用uiwebviewdelegate的webVIEw:shouldStartLoaDWithRequest:navigationType:方法.

问题是,当我点击此搜索页面上的后退按钮时,没有代表被调用,所以我在禁用后退按钮时出现问题.

此问题仅发生在不在iPhone应用程序中的iPad应用程序中.

解决方法 这段代码可以帮助你……

UIWebVIEw是一个UIVIEw,可以在用户的​​应用程序中加载网页.
通过在网页本身中使用嵌入链接,允许导航到其他网页.可以使用实例方法goForward和goBack设置历史记录的前进和后退导航,但程序员必须提供按钮.

以下示例使用UIWebVIEw和

1)添加前进和后退按钮.使用uiwebviewdelegate可选方法webVIEwDIDStartLoad:和webVIEwDIDFinishLoad启用并突出显示按钮:

2)添加一个UIActivityIndi​​catorVIEw,在网页加载时显示

在WebVIEwController的.h文件中:

声明UIWebVIEw,可选:添加按钮以控制前进和后退浏览历史记录和IBActions按下按钮,可选:再次添加UIActivityIndi​​catorVIEw.

@interface WebVIEwController : UIVIEwController <uiwebviewdelegate>{    UIWebVIEw *webVIEw;    UIbutton *back;    UIbutton *forward;    UIActivityIndicatorVIEw *activityIndicator;}@property(nonatomic,retain)IBOutlet UIWebVIEw *webVIEw;@property(nonatomic,retain)IBOutlet UIbutton *back;@property(nonatomic,retain)IBOutlet UIbutton *forward;@property(nonatomic,retain)IBOutlet UIActivityIndicatorVIEw *activityIndicator;-(IBAction)backbuttonpressed: (ID)sender;-(IBAction)forwardbuttonpressed: (ID)sender;@end

//在WebVIEwController的.m文件中

@implementation WebVIEwController@synthesize webVIEw;@synthesize back;@synthesize forward;@synthesize activityIndicator;//method for going backwards in the webpage history-(IBAction)backbuttonpressed:(ID)sender {    [webVIEw goBack]; }//method for going forward in the webpage history-(IBAction)forwardbuttonpressed:(ID)sender{    [webVIEw goForward];}//programmer defined method to load the webpage-(voID)startWebVIEwLoad{    //Nsstring *urlAddress = @"http://www.Google.com";    Nsstring *urlAddress = @"http://cagt.bu.edu/page/IPhone-summer2010-wiki_problemsandsolutions";    //Create a URL object.    NSURL *url = [NSURL URLWithString:urlAddress];    //URL Requst Object    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];    //Load the request in the UIWebVIEw.    [webVIEw loadRequest:requestObj];}// acivityIndicator is set up here- (voID)vIEwDIDLoad {    //start an animator symbol for the webpage loading to follow    UIActivityIndicatorVIEw *progressWheel = [[UIActivityIndicatorVIEw alloc] initWithActivityIndicatorStyle:UIActivityIndicatorVIEwStyleGray];    //makes activity indicator disappear when it is stopped    progressWheel.hIDesWhenStopped = YES;    //used to locate position of activity indicator    progressWheel.center = CGPointMake(160,160);    self.activityIndicator = progressWheel;    [self.vIEw addSubvIEw: self.activityIndicator];    [self.activityIndicator startAnimating];    [progressWheel release];    [super vIEwDIDLoad];    //call another method to do the webpage loading    [self performSelector:@selector(startWebVIEwLoad) withObject:nil afterDelay:0];  }- (voID)dealloc {    [webVIEw release];    [back release];    [forward release];    [activityIndicator release];    [super dealloc];}#pragma mark uiwebviewdelegate methods//only used here to enable or disable the back and forward buttons- (voID)webVIEwDIDStartLoad:(UIWebVIEw *)thisWebVIEw{    back.enabled = NO;    forward.enabled = NO;}- (voID)webVIEwDIDFinishLoad:(UIWebVIEw *)thisWebVIEw{    //stop the activity indicator when done loading    [self.activityIndicator stopAnimating];         //canGoBack and canGoForward are propertIEs which indicate if there is         //any forward or backward history    if(thisWebVIEw.canGoBack == YES)    {        back.enabled = YES;        back.highlighted = YES;    }    if(thisWebVIEw.canGoForward == YES)    {        forward.enabled = YES;        forward.highlighted = YES;    }}@end

/ ********* /

//In vIEwDIDLoad for the class which adds the WebVIEwController:WebVIEwController *ourWebVC = [[WebVIEwController alloc] initWithNibname:@"WebVIEwController" bundle:nil];ourWebVC.Title = @"WebVIEw";[self.vIEw addSubvIEw:ourWebVC];//release ourWebVC somewhere else
总结

以上是内存溢出为你收集整理的ios – iPad中的UIWebView后退按钮实现问题全部内容,希望文章能够帮你解决ios – iPad中的UIWebView后退按钮实现问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1078531.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存