webViewDidStartLoad isn't doing anything

Discussion in 'iOS Development' started by Freerunnering, Jun 18, 2010.

  1. Freerunnering

    Freerunnering Member

    Joined:
    Sep 1, 2009
    Messages:
    296
    Likes Received:
    0
    Device:
    4G iPod touch
    I've been trying to get an activity indicator to work for my app but it just wouldn't work no matter what i did!

    So i decided to test my activity indicator code by putting it in the viewDidLoad function to see if that was broken but it worked so i know that it's the webViewDidStartLoad that's not working but i don't know why?

    I put an alert in the webView start load to see if it does anything and it doesn't!

    My UiWebView is called webView and this code snippet is a few lines beneath the webView load url request which works.

    [objc]
    - (void)webViewDidStartLoad

    Please Register or Log in to view images

    UIWebView *)webView {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    }
    [/objc]


    Also note i'm quite new to iPhone development and so if it's a simple thing i've completely missed please point it out?
  2. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    Have you set the delegate of the webview?
  3. Freerunnering

    Freerunnering Member

    Joined:
    Sep 1, 2009
    Messages:
    296
    Likes Received:
    0
    Device:
    4G iPod touch
    The webView works fine it's just the webViewDidStartLoad doesn't do anything.
    I put that code in the view controller as that's where the webView is controlled from not the app delegate if that makes a difference??
    ------------------double post merged------------------
    The App is a view based app.

    I don't think i've touched the app delegate files but here's my view controller files.


    APP_BetaViewController.h
    [objc]
    //
    // APP_BetaViewController.h
    // APP Beta
    //
    // Created by H4CK3R on 15/06/2010.
    // Copyright __MyCompanyName__ 2010. All rights reserved.
    //

    #import <UIKit/UIKit.h>

    @interface APP_BetaViewController : UIViewController {
    IBOutlet UIWebView *webView;
    }

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

    -(IBAction)HOME;
    @end
    [/objc]



    APP_BetaViewController.m

    [objc]
    //
    // APP_BetaViewController.m
    // APP Beta
    //
    // Created by H4CK3R on 15/06/2010.
    // Copyright __MyCompanyName__ 2010. All rights reserved.
    //

    #import "APP_BetaViewController.h"

    @implementation APP_BetaViewController
    @synthesize webView;


    -(IBAction)HOME{
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString

    Please Register or Log in to view images

    "http://google.com/"]]];
    }


    /*
    // The designated initializer. Override to perform setup that is required before the view is loaded.
    - (id)initWithNibName

    Please Register or Log in to view images

    NSString *)nibNameOrNil bundle

    Please Register or Log in to view images

    NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
    // Custom initialization
    }
    return self;
    }
    */

    /*
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {
    }
    */



    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
    [super viewDidLoad];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString

    Please Register or Log in to view images

    "http://youtube.com"]]];
    }

    /*
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation

    Please Register or Log in to view images

    UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    */

    - (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
    }

    - (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    }

    - (void)webViewDidStartLoad

    Please Register or Log in to view images

    UIWebView *)webView {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    }

    - (void)webViewDidFinishLoad

    Please Register or Log in to view images

    UIWebView *)webView {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    }

    - (void)dealloc {
    [webView release];
    [super dealloc];
    }

    @end
    [/objc]
  4. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    You're not setting the webview's delegate. Make sure to set it somewhere in your view controller (should be done in -viewDidLoad).

    See the docs.
  5. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    Maybe the delegate was set in Interface Builder (by ctrl-dragging from the web view to the app delegate), but you still need to make sure it's assigned somehow.
  6. Freerunnering

    Freerunnering Member

    Joined:
    Sep 1, 2009
    Messages:
    296
    Likes Received:
    0
    Device:
    4G iPod touch
    But i'm not using the app delegate at all??
  7. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    UIWebView delegate != AppDelegate.

    You're telling your webview who wants to be notified and called by setting its delegate.


    @lauNchD Good point about the possible connection done in IB.
  8. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    The delegation pattern is very prevalent in Cocoa. For your sake, you should read about it. This article demonstrates work or "decision-making" delegated to another object. Also, as we see in this case, notifications can be sent, dynamically and anonymously (the sender of the delegate messages doesn't know what the delegate is, just that it exists and implements certain methods.

    Skylar posted something about formal protocols and delegation that would be of help; it shouldn't be hard to find.
  9. Freerunnering

    Freerunnering Member

    Joined:
    Sep 1, 2009
    Messages:
    296
    Likes Received:
    0
    Device:
    4G iPod touch
    I'm sorry i still don't understand? can you show me be putting whatever it is in the source code i posted above??
  10. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    [objc]-(void)viewDidLoad{
    [webview setDelegate:self];
    }[/objc]

    For your sake, understand delegates before even copying and pasting that to your code.

Share This Page