0

I have an apps written with Objective C. I can't load web page to UIWebView. UIWebViewDelegate not working. My app code ;

#import <UIKit/UIKit.h>

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

I did it this way .m page. webViewDidFinishLoad and webView didFailLoadWithError: not working.

#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;
}

I have, ios 8 device, xcode 6.3. I'm sorry for my bad english. thanks ...

sem sur
  • 21
  • 3
  • it's been a while then, but I think you have to create delegate reference on storyboard in order to make the delegate methods work. – RyanB May 27 '16 at 02:10

1 Answers1

0

You need to check how you are initiating the Reklamlarim view because

- (id)initWithFrame:(CGRect)frame

is only calling when you are initiating from some where and call this init function it doesn't call automatically.. so move [self webSayfasiYukle]; to

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

like this and try.

andykkt
  • 1,696
  • 16
  • 23