2014-01-07 32 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; 
}