views:

112

answers:

5

Hi!

I'm trying to play with a WebView.

I made an outlet:

IBOutlet UIWebView *browser;

Defined it as a property:

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

Synthethized it:

@synthesize browser;

Finally, I connected it in Interface Builder, really it is.

Then I try to do something with it i.e.:

[browser loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://apple.com"]]];

Or also:

Etape *etape = [[Etape alloc] init];

NSString *html = [etape generateHTMLforEtape:[current_etape objectAtIndex:0]];
[browser loadHTMLString:html baseURL:nil];

[etape release];

I get no errors, I tried to Build & Analyse, no notices or warnings or errors.. I've been searching for one whole day, please help me :/

Thanks a lot!

EDIT: Here's screenshots of my connections for my WebView: Connections

EDIT: That is how I call the view:

    DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];

    dvController.workflow_id = parent_id;

    Etape *etape = [[Etape alloc] init];
    dvController.etapes = [etape getEtapes:parent_id];
    [etape release];

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

    [dvController release];
+2  A: 

Some thoughts:

Depending on which method you're running this code in, the outlets might not be hooked up yet. The most common place to begin interacting with your outlets is in a viewDidLoad, viewWillAppear: or viewDidAppear: method, after the call to super's implementation. If you're trying to do this in your init method, your outlets are probably still nil. The nib isn't loaded and the outlets aren't hooked up until somebody requests the view of your viewcontroller. Might this be what you're experiencing?

If you NSLog(@"%@", browser); in a method where you know the view should exist, but get (null) logged, then it's a sign that your outlets have lost their connections somehow.

EDIT #1 Are you sure you have the name of your xib spelled correctly when you call initWithNibName:bundle:? (btw, you can pass in nil for the bundle, and it will assume [NSBundle mainBundle])

Dave DeLong
@Dave DeLong: My samples are currently in: - (void)viewDidLoad {} so this shouldn't be a a problem.But if I NSLog my browser object I currently get: (null)This is really weird... Thanks for the help
Tom
Yes I have the right one (I double-checked)... Thanks
Tom
+1  A: 

One thing is that you may have wired it to the @property OR to the IBOutlet (in my experience Interface Builder gets confused easily). Maybe try declaring as:

UIWebView *browser_;
@property (nonatomic, retain) IBOutlet UIWebView *browser;
@synthesize browser=browser_;
Steven Canfield
If I do what you told me my browser_ is still (null) :/ Thanks for the help anyways! :)
Tom
+1  A: 

It could be due to the way you're initing the view. If the view controller is being loaded in code then you'll need to ensure that its' view is being loaded too.

To do this init the view controller with initWithNibName:bundle: and ensure that 'file owner' in the NIB which contains the view is set to the class name of the view controller.

Benedict Cohen
Hum I'm not sure that I understand it all but anyways that's how I call this view: (not a good idea to paste this here, look in the question ^^) Thanks
Tom
+1  A: 

One explanation is that the browser is not being retained because your not using the "self.attribute" construction to call the synthesized setter that does the retaining. The browser is loading in the nib but by the time you get around to using it has been released.

Try switching "browser" to "self.browser" and see if that resolves the problem.

TechZen
Unfortunately, it doesn't change a thing :/ Thanks anyways
Tom
Well, you've missed something. Obviously, people hook up UIWebViews all the time. If the project is small, post up on line somewhere and let us look it over. I suspect you don't actually have it wired up properly in IB.
TechZen
@TechZen `self.browser` shouldn't change anything; the nib loader invokes `setBrowser:` while loading, so it should be retained already. In addition, `self.browser` (in the context you're describing) is the getter, which has nothing to do with retaining.
Dave DeLong
@Dave Delong -- You're probably right, however, I've seen enough cases where self-dot solves the problem that always recommending its use is always prudent.
TechZen
@TechZen intriguing. I'd love to see an example! :)
Dave DeLong
@Dave Delong -- So would I, if only to save me the public humiliation. I remember fixing a nib problem with self notation but I can't remember the details. In any case, using the self-dot notation is good practice.
TechZen
+1  A: 

I've had this problem before. It LOOKS connected, but things just don't work. I hate to say it, but have you tried restarting Xcode? (I've had this problem before, and, well, restarting Xcode resolved the issue.)

Frank Shearar
I was so happy to see this, I was like "eh, something so simple?!". But unfortunately it did not worked :/ Thanks anyways :)
Tom