我想用WKWebView爲iOS8上,但還需要IOS7兼容性,我見過的帖子提到使用此代碼:的UIWebView和WKWebView
if ([WKWebView class]) {
// do new webview stuff
}
else {
// do old webview stuff
}
但不知道我在做什麼錯了,因爲下面的代碼給了我一個鏈接錯誤:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_WKWebView", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
任何幫助非常感謝,這是我的代碼:
.h文件中:
#import "WebKit/WebKit.h"
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *contentWebView;
@property (weak, nonatomic) IBOutlet WKWebView *contentWKWebView;
@end
.m文件:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
@synthesize contentWebView;
@synthesize contentWKWebView;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"LockBackground" ofType:@"html"];
NSURL * fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
NSURLRequest * myNSURLRequest = [[NSURLRequest alloc]initWithURL:fileURL];
if ([WKWebView class]) {
[contentWKWebView loadRequest:myNSURLRequest];
} else {
[contentWebView loadRequest:myNSURLRequest];
}
}
-(UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我想你不能在這種情況下使用IBOutlet。如果您將WKWebView添加到xib或故事板,則iOS 8下無法加載xib或故事板。 – Ryan
如何解決此問題? – Nicoll
怎樣通過代碼分配一個webView。不與xib或故事板。 – Ryan