0

I am working on an app that receives a feed that I display in a UIWebView. The feed has embedded links that I want to open in Safari instead of thew WebView. I have looked over several other questions that are posted here. I am not sure what I am missing, but I think it is something simple. Here are my .h and .m files

#import 
@class BlogRss;


@interface EnduranceDailyWorkoutViewController : UIViewController {
    IBOutlet UIWebView * descriptionTextView;
    BlogRss * currentlySelectedBlogItem;
}

@property (nonatomic, retain) UIWebView * descriptionTextView;
@property (readwrite, retain) BlogRss * currentlySelectedBlogItem;
@end
#import "EnduranceDailyWorkoutViewController.h"
#import "BlogRss.h"

@implementation EnduranceDailyWorkoutViewController


@synthesize descriptionTextView = descriptionTextView;
@synthesize currentlySelectedBlogItem = currentlySelectedBlogItem;

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *html = [NSString stringWithFormat:@"%@ %@",currentlySelectedBlogItem.title, currentlySelectedBlogItem.contentEncoded];
    [descriptionTextView loadHTMLString:html baseURL:[NSURL URLWithString:nil]];

}

-(BOOL)webView:(UIWebView *)descriptionTextView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if (UIWebViewNavigationTypeLinkClicked == navigationType) {
        [[UIApplication sharedApplication] openURL:[request URL]];
        return NO;
    }
    return YES;
}

Using Interface Builder I have linked the IBOutlet and the UIWebView. Please let me know what I am missing. I have put break points in the webView section but the code never hits there so it is almost like something is not linked correctly in IB.

James
  • 493
  • 1
  • 10
  • 37

1 Answers1

1

You need to ensure that the UIWebView's delegate is set to your controller. You can do this in interface builder, or you can modify your viewDidLoad method:

- (void)viewDidLoad {
    [super viewDidLoad];
    // add this line to set the delegate of the UIWebView
    descriptionTextView.delegate = self;
    NSString *html = [NSString stringWithFormat:@"%@ %@",currentlySelectedBlogItem.title, currentlySelectedBlogItem.contentEncoded];
    [descriptionTextView loadHTMLString:html baseURL:[NSURL URLWithString:nil]];
}
Greg
  • 33,450
  • 15
  • 93
  • 100
  • GreginYEG, Thanks for the help. I was forgetting to set the delegate. I thought I had done that in Interface Builder but apparently not. – James Mar 21 '11 at 09:51