UIWebView没有加载委托

时间:2015-06-07 14:53:35

标签: ios objective-c uiwebview uiwebviewdelegate

我有一个用Objective C编写的应用程序。我无法将网页加载到UIWebView。 UIWebViewDelegate无法正常工作。我的应用代码;

#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 *url=@"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。我很抱歉我的英语不好。 谢谢...

1 个答案:

答案 0 :(得分:0)

您需要检查启动Reklamlarim视图的方式,因为

- (id)initWithFrame:(CGRect)frame

只在你从某个地方开始调用时调用它不会自动调用它的init函数。所以移动[self webSayfasiYukle];到

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

像这样试试。