2015-06-07 88 views
0

我有一個用Objective C編寫的應用程序。我無法加載網頁到UIWebView。 UIWebViewDelegate無法正常工作。我的應用代碼;UIWebView不加載委託

#import <UIKit/UIKit.h> 

@interface Reklamlarim : UIView <UIWebViewDelegate> 
- (void)webSayfasiYukle; 
@end 

我這樣做了.m頁面。 webViewDidFinishLoad和webView didFailLoadWithError:無法正常工作。

#import "Reklamlarim.h" 


@implementation Reklamlarim 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     [self webSayfasiYukle]; 
    } 
    return self; 
} 

- (void)webSayfasiYukle{ 
    NSLog(@"webSayfasiYukle"); 

    UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
    webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 
    webView.delegate = self; 

    NSString *[email protected]"http://www.google.com"; 
    NSURL *nsurl=[NSURL URLWithString:url]; 
    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl]; 
    [webView loadRequest:nsrequest]; 
    [self addSubview:webView]; 
} 


- (void)webViewDidFinishLoad:(UIWebView *)webView { 
    NSLog(@"webViewDidFinishLoad"); 
} 
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { 
    NSLog(@"webView didFailLoadWithError"); 

} 

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

我有,ios 8設備,xcode 6.3。我很抱歉我的英文不好。 感謝...

+0

已經有一段時間了,但我認爲你必須在故事板上創建委託引用,以使委託方法有效。 – RyanB

回答

0

你需要檢查你是如何啓動Reklamlarim觀點,因爲

- (id)initWithFrame:(CGRect)frame 

當你從那裏的一些啓動和調用這個初始化函數它不會自動調用只調用。如此移動[self webSayfasiYukle];到

-(void)awakeFromNib { 
    [self webSayfasiYukle]; 
} 

這樣並嘗試。