【发布时间】:2014-12-23 06:15:30
【问题描述】:
我想在 IOS8 上使用 WKWebView,但也需要与 IOS7 兼容,我看到过使用此代码的帖子:
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 或 storyboard,则 xib 或 storyboard 无法在 iOS 8 以下加载。
-
请问如何解决这个问题?
-
如何通过代码分配一个 webView。不适用于 xib 或情节提要。
-
我只有一个带有 2 个属性的 webView(不确定这是否好用),我应该有 2 个 webViews 吗?您能否举例说明如何在没有 IBOutlet 的情况下对其进行编码?谢谢你。
-
id webView; if([WKWebView class]) { webView = [[WKWebView alloc] init]; } else { webView = [[UIWebView alloc] init]; }像这样。
标签: objective-c xcode wkwebview