0

ここでこれに関する3つまたは4つの投稿を試しましたが、ファイルパスを使用するものはなく、WKWebViewでこれを機能させることができません。UIWebViewで機能します。誰か助けてください。はい、私はこれに非常に慣れていません。今夜ここに投稿する前に一日中試したので、わかりやすい指示は素晴らしいでしょう. ありがとう。

.h ファイル:

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *contentWebView;
@end

.m ファイル:

#import "ViewController.h"
@interface ViewController ()
@end

@implementation ViewController
@synthesize contentWebView;

- (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];
    [contentWebView loadRequest:myNSURLRequest];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

1 に答える 1

1

単純に変化する

@property (weak, nonatomic) IBOutlet UIWebView *contentWebView;

@property (weak, nonatomic) IBOutlet WKWebView *contentWebView;

動作するはずです。


iOS 7 と iOS 8 の両方をサポートする場合は、2 つの変数を宣言し、次の検証を追加する必要があります。

if ([WKWebView class]) {
    // do new webview stuff
}
else {
    // do old webview stuff
}
于 2014-12-22T14:12:28.563 に答える