UIWebView IBOutlet is always nil

  • I have a UINavigationController-based app that I would like to use a
    UIWebView to show an HTML page.  My problem is that I declare my UIWebView
    property as an IBOutlet, and it is always nil.

    This is apparently a very common problem.  Google turns up lots of queries
    at StackOverflow.  I read them all, but no joy.

    I tried deleting my build folder, and my built app, but that didn't help.

    My XIB file has a UIView with the UIWebView on top of it.  Is that
    correct?  Or am I supposed to use a UIWindow?

    The file's owner has the IBOutlet that references the UIWebView.  I've
    tried connecting the file's owner "view" IBOutlet both to the file-scoped
    view, and to the UIWebView.

    The file's owner is declared as a ManualViewControllerIOS in the Identity
    inspected.

      // ManualViewControllerIOS.h
      #import <UIKit/UIKit.h>

      @interface ManualViewControllerIOS : UIViewController {

      }

      @property (retain,nonatomic) IBOutlet UIWebView *webView;

      @end

        // ManualViewControllerIOS.m
      #import "ManualViewControllerIOS.h"

      @implementation ManualViewControllerIOS

      @synthesize webView;

      - (void) viewDidAppear: (BOOL) animated
      {
          [super viewDidAppear: animated];

          NSString *manualIndex;

          NSBundle *mainBundle = [NSBundle mainBundle];

          manualIndex = [mainBundle pathForResource:
                      @"index" ofType: @"html"];

          NSLog( @"%@", webView );

          [webView loadRequest:
            [NSURLRequest requestWithURL:
            [NSURL URLWithString: manualIndex]]];
      }
      @end

    Here is how I push my view controller onto the UINavigationController stack:

      - (IBAction) manual: (id) sender
      {
          ManualViewControllerIOS *manualViewController [[[ManualViewControllerIOS alloc] init] autorelease];

          [self.navigationController pushViewController: manualViewController
    animated: YES];

          return;
      }

    My App is quite complex, so I'm writing an online manual.  At first I was
    loading it from my website, but that doesn't satisfy when the Internet is
    out of reach.  UIWebView would be the cat's meow if I could get it to work.

    Thanks for any help you can give me,

    Mike
    --
    Michael David Crawford
    mdcrawford at gmail dot com
  • On 5 May 2013, at 6:47 PM, Michael Crawford <mdcrawford...> wrote:

    > @property (retain,nonatomic) IBOutlet UIWebView *webView;
    ...
    > @synthesize webView;
    ...
    > NSLog( @"%@", webView );

    I've seen this before, but only in the case where there was no @synthesize; did your actual code use it?

    In recent compilers, if the getter and setter for a property are generated without @synthesize, the backing variable would be named _webView. When I ran into the bug, the coder had defined a global of the same name, which masked the error from the compiler.

    But my experiment shows that if you use @synthesize, the backing ivar is named without the underscore. If your production code is as you show, I'm not helping you here.

    — F

    --
    Fritz Anderson
    Xcode 4 Unleashed: 4.5 supplement for free!
    http://www.informit.com/store/xcode-4-unleashed-9780672333279
  • > I've seen this before, but only in the case where there was no
    @synthesize; did your actual code use it?

    Yes.

    My best guess is that it's some corruption in the nib.  I'll make a
    standalone App with nothing but a UIWebView in it.  Maybe if that works I
    could just copy the xib over to my production project.

    Or maybe it's a bug in the simulator.  I don't have a device to test on
    right now, as my iPhone was stolen.  I'm planning on getting an iPod Touch,
    but not for a little while.

    If I can't get it working I'll file a Radar.

    Thanks for your help.

    Mike Crawford
    <mdcrawford...>

    On Fri, May 10, 2013 at 5:34 AM, Fritz Anderson <fritza...>wrote:

    > On 5 May 2013, at 6:47 PM, Michael Crawford <mdcrawford...> wrote:
    >
    >> @property (retain,nonatomic) IBOutlet UIWebView *webView;
    > ...
    >> @synthesize webView;
    > ...
    >> NSLog( @"%@", webView );
    >
    > I've seen this before, but only in the case where there was no
    > @synthesize; did your actual code use it?
    >
    > In recent compilers, if the getter and setter for a property are generated
    > without @synthesize, the backing variable would be named _webView. When I
    > ran into the bug, the coder had defined a global of the same name, which
    > masked the error from the compiler.
    >
    > But my experiment shows that if you use @synthesize, the backing ivar is
    > named without the underscore. If your production code is as you show, I'm
    > not helping you here.
    >
    > — F
    >
    >
    >
    > --
    > Fritz Anderson
    > Xcode 4 Unleashed: 4.5 supplement for free!
    > http://www.informit.com/store/xcode-4-unleashed-9780672333279
    >
    >

    --
    Michael David Crawford
    mdcrawford at gmail dot com

      Custom Software Development for the iPhone and Mac OS X
      http://www.dulcineatech.com/custom-software-development/
  • Sorry, I missed the beginning of this thread, so apologies if these suggestions have already been covered.

    When in that case, I make sure to delete the UIWebView in the storyboard, create another one and reconnect the outlet to the property in the class.

    Did you create the IBOutlet property in the header file or the method file?

    If the little circle next to the property is always empty, it's not being regarded as being properly hooked up.

    Try mousing over the little circle and see if it shows the storyboard it's connected to.

    If you want, send me some screenshots and I'll try to help diagnose the patient.

    Cheers.

    On May 12, 2013, at 11:35 AM, Michael Crawford wrote:

    >> I've seen this before, but only in the case where there was no
    > @synthesize; did your actual code use it?
    >
    > Yes.
    >
    > My best guess is that it's some corruption in the nib.  I'll make a
    > standalone App with nothing but a UIWebView in it.  Maybe if that works I
    > could just copy the xib over to my production project.
    >
    > Or maybe it's a bug in the simulator.  I don't have a device to test on
    > right now, as my iPhone was stolen.  I'm planning on getting an iPod Touch,
    > but not for a little while.
    >
    > If I can't get it working I'll file a Radar.
    >
    > Thanks for your help.
    >
    > Mike Crawford
    > <mdcrawford...>
    >
    >
    > On Fri, May 10, 2013 at 5:34 AM, Fritz Anderson <fritza...>wrote:
    >
    >> On 5 May 2013, at 6:47 PM, Michael Crawford <mdcrawford...> wrote:
    >>
    >>> @property (retain,nonatomic) IBOutlet UIWebView *webView;
    >> ...
    >>> @synthesize webView;
    >> ...
    >>> NSLog( @"%@", webView );
    >>
    >> I've seen this before, but only in the case where there was no
    >> @synthesize; did your actual code use it?
    >>
    >> In recent compilers, if the getter and setter for a property are generated
    >> without @synthesize, the backing variable would be named _webView. When I
    >> ran into the bug, the coder had defined a global of the same name, which
    >> masked the error from the compiler.
    >>
    >> But my experiment shows that if you use @synthesize, the backing ivar is
    >> named without the underscore. If your production code is as you show, I'm
    >> not helping you here.
    >>
    >> — F
    >>
    >>
    >>
    >> --
    >> Fritz Anderson
    >> Xcode 4 Unleashed: 4.5 supplement for free!
    >> http://www.informit.com/store/xcode-4-unleashed-9780672333279
    >>
    >>
    >
    >
    > --
    > Michael David Crawford
    > mdcrawford at gmail dot com
    >
    > Custom Software Development for the iPhone and Mac OS X
    > http://www.dulcineatech.com/custom-software-development/
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today