1

I am having an issue getting UIWebView as an outlet. I've done my research, here are the steps I've taken.

Using XCode 5.0.1

  • Created a ViewController named WebViewController with XIB

  • Verified fileowner is WebViewController

  • added a UIWebView to the xib

  • set UIWebView delegate to FileOwner WebViewController

  • modified WebViewController.h, adding

  • Adding the following methods to WebViewController.m

    1. (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    2. (void)webViewDidFinishLoad:(UIWebView *)webView
    3. (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
    4. (void)webViewDidStartLoad:(UIWebView *)webView
  • Create an outlet from UIWebView to myWebView (in the .m file)

As soon as I push the WebViewController I get a NSUnknownKeyException on myWebView.

 *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<WebViewController 0x19ff75a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myWebView.'

IMPORTANT: If I merely remove the outlet to myWebView then I can push the WebViewController fine. Of course I cannot modify the UIWebView though with no outlet.

Any idea what is going on here? I get the same issue in a new/blank project as well.

UPDATE: - So WebViewController.xib FIleOwner custom class is: WebViewController, verified in InterfaceBuilder - Creation at runtime is like this

 [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
  • Breakpoint set at initWithNibName in WebViewController.m never fires.
Halsafar
  • 2,540
  • 4
  • 29
  • 52

3 Answers3

0

from the error message, seems that your UIWebView in xib is already connected to outlet named myWebView, but the outlet variable is not in .m or .h; try to right click on your UIWebView in xib file, and remove the connected outlet.

EDIT

if that trick didn't work. try to remove myWebView manually from the xib. here the steps :

  • right click on xib, click Open As, click on Source Code
  • you will get xml code of the xib, try to find (ctrl + f) using myWebView keyword
  • remove it
Community
  • 1
  • 1
novalagung
  • 10,905
  • 4
  • 58
  • 82
  • Yes I realize that is what this error message usually means but this is clearly not the cause this time. Removing the outlet makes it work, adding it back in fresh fails on NSUnknownKeyException. – Halsafar Feb 05 '14 at 22:03
  • I've updated my answer, please check it – novalagung Feb 05 '14 at 22:07
  • I don't think you are understand. I can already remove the outlet, no issues there. Removing the outlet makes the exception go away. I need the outlet however. Adding it back in causes exception. – Halsafar Feb 05 '14 at 22:10
0

Make sure you added your WebViewController to your target. Tap on WebViewController.m check Target Membership. Make sure checkbox is selected.

enter image description here

Gago
  • 297
  • 1
  • 9
  • I have verified they are in the build targets. Also as since merely by removing the UIWebView to myWebView outlet I can push this WebViewController just fine. – Halsafar Feb 05 '14 at 22:04
  • Do you have another outlets in that XIB connected with controller? – Gago Feb 05 '14 at 22:05
  • WebViewController.xib has only a UIWebView. The UIWebView has 1 outlet, delegate->File Owner and 1 referencing outlet myWebView->File Owner. – Halsafar Feb 05 '14 at 22:07
  • I believe this is connected with target. Try to Clean project. If will not help try to create Controller and Xib again. – Gago Feb 05 '14 at 22:11
  • Cleaned 100 times before I posted on SO. – Halsafar Feb 05 '14 at 22:11
  • There is another point too. You do not need to verify fileOwner when you are creating Xib with controller – Gago Feb 05 '14 at 22:25
0

So I changed the name of the files after discovering this:

https://developer.apple.com/library/ios/samplecode/uicatalog/listings/ViewControllers_WebViewController_m.html

Now everything works perfect. The steps I listed in the question work just fine to create a UIWebView.

Halsafar
  • 2,540
  • 4
  • 29
  • 52