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。我很抱歉我的英文不好。 感謝...
已經有一段時間了,但我認爲你必須在故事板上創建委託引用,以使委託方法有效。 – RyanB