开发者

I can't get UIWebViewDelegate to work

I'm trying to implement a UIWebViewDelegate in my application and I cannot for the life of me get it to work. I would really appreciate a second set of eyes on this.

I know the name MapViewController is confusing, but the WebView is controlling a map (not UIMapView).

Here's the bulk of the code:

MapViewController.h

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

@interface MapViewController : UIViewController<UIWebViewDelegate> {
    IBOutlet UIWebView *webView;
}

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

@end

MapViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    webView.delegate = self;
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"map" ofType:@"html"]isDirectory:NO]];
    [webView loadRequest:request];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    NSLog(@"Done loading.");
}
- (BOOL)w开发者_StackOverflowebView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"hi");
    return NO;
}
- (void)dealloc {
    webView.delegate = nil;
    [webView release]
    [super dealloc];
}

Thanks for any help!


Does the initial page you're loading actually display? Are you sure you connected your webview in Interface Builder?


go interface builder , connect the delegate to the file's owner , then it should work.

  1. Open Interface Builder
  2. Right click on the Web View object
  3. Drag the delegate onto files owner.


Things to check:

  1. if map.html is in the bundle. Put it on the root of the bundle, not on resources.
  2. if it is, right click on it, and choose get info. Verify on TARGETS if the target is checked for the file.


- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"hi");
    return YES; // for all supported oreintation.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜