0

I'm pretty new to Objective-C/iOS Dev as a whole and am going grey over this. I can not seem to get WKWebkit working for the life of me.

After extensive Google Searches, I finally put together some code that compiles - buuuut the app crashes.

WebView.h

#import <UIKit/UIKit.h>
#import <Webkit/Webkit.h>
#import <objc/runtime.h>

@interface WebViewController: UIViewController <WKUIDelegate>;
@property (nonatomic, strong) WKWebView *webView
@end

WebView.m

@implementation WebViewController
-(void) viewDidLoad {
    [super viewDidLoad];
    if (NSClassFromString(@"WKWebView")) {
        _webView = [[WKWebView alloc] initWithFrame:[[self view] bounds]];
    } else {
        _webView = [[UIWebView alloc] initWithFrame:[[self view] bounds]];
    }
    NSString *urlString = @"http://www.google.com";
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:urlRequest];
}
@end

I do have the class set as WebViewController under custom class in the storyboard, as well.

Here is the error message I keep getting:

[WebViewController superview]: unrecognized selector sent to instance 0x7fdbb570e050

Any clue what I'm doing wrong? I'm still too unfamiliar to catch any obvious bugs myself. Thank you so much!

bbug333
  • 19
  • 1
  • 5

1 Answers1

0

What the error says is that your class WebViewController does not have a method superview. Unfortunately I can not see the issue in the code you posted and assume it is somewhere else. Although the code itself is still very iffy.

You could use exception breakpoints which should show you exact line that is causing this and add that information.

In general I can assume that you are somehow using your class in place of UIView. An UIViewController is not a subclass of UIView so it does not have a method superview.

Matic Oblak
  • 16,318
  • 3
  • 24
  • 43