即使使用Delegate = self并且还实现了UIWebView委托协议,也不会调用WebView委托

时间:2014-01-07 14:07:09

标签: ios objective-c uiwebview

//NewCharts.h

#import <UIKit/UIKit.h>
@interface NewCharts : UIViewController<UIWebViewDelegate>
@property(nonatomic,retain)IBOutlet UIWebView *webView;
@property(nonatomic,retain)IBOutlet UIActivityIndicatorView *loadView;
@end

//NewChart.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title=@"Charts";
    NSURL *url=[[NSURL alloc]initWithString:[NSString stringWithFormat:@"www.google.com"]];
    NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url];
    [_webView loadRequest:request];
    _webView.scalesPageToFit=YES;
    _webView.delegate=self;
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}

-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [_loadView startAnimating];

}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_loadView stopAnimating];
}

//我使用xib文件进行设计并将其引用和委托连接到文件的所有者。代理人仍然没有被调用。我只能看到页面的标题。

1 个答案:

答案 0 :(得分:1)

使用 http:// 加载网址,尝试按照

NSURL *url=[[NSURL alloc]initWithString:[NSString stringWithFormat:@"http://www.google.com"]];