2014-01-07 31 views
0
//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. 
    [email protected]"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文件进行了设计,并将其引用和委托连接到文件的所有者。仍然不调用委托。我只能看到页面的标题。即使使用Delegate = self也不会调用WebView委托并且还实现了UIWebView委托协议

+0

有检查把破发点中的请求之前,委托方法? –

回答

2

载入URL与的http://,试试以下

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

呼叫Self.webview.delegate =自我加载到的WebView

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