0

I have a UIViewController inside of which I put a UIWebView

Then I added this to the .h file:

#import <UIKit/UIKit.h>

@interface BuildBusinessController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *theWebView;

@end

and have this as the .m file

#import "BuildBusinessController.h"

@interface BuildBusinessController ()

@end

@implementation BuildBusinessController
@synthesize theWebView;

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    theWebView.delegate = self;
}

- (void)viewDidUnload
{
    [self setTheWebView:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)viewDidAppear:(BOOL)animated
{  
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"build_business" ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:htmlFile];
    NSURLRequest *rq = [NSURLRequest requestWithURL:url];
    [theWebView loadRequest:rq];
}

@end

But the build_business.html file is not rendering inside the view, and also I get a warning on this line: theWebView.delegate = self; which says:

Assigning to id 'UIWebViewDelegate from incompatible type BuildBusinessController *const_string

Would anyone know what I am doing wrong here? It feels I am forgetting some one small thing :)

2 Answers 2

1

In addition to F.X. answer, I think you forgot to add this in viewDidAppear (after loadRequest):

[self.view addSubview:theWebView];

Update: The issue is caused by OP failing to configure delegate for UIWebView in Storyboard. The code snippet provided here will only work if you are coding it manually. Otherwise, as stated by @F.X. in the comments below, Storyboard will implement this automatically.

Sign up to request clarification or add additional context in comments.

6 Comments

sorry, where exactly should that line be? I am not noticing the loadRequest - you mean as the last line in viewDidAppear - that didn't work.
Just to check, did you create the web view using storyboard?
yes I created the view using the storyboard, but I wrote the code manually, which might be the problem.
I wasn't sure how to align the windows of xcode so I can drag the arrow from the storyboard to the .h file
@AlanYeo: There's no need for that, the Storyboard automatically creates and adds the view :)
|
1

You're just forgetting UIWebViewDelegate on your class definition :

#import <UIKit/UIKit.h>

@interface BuildBusinessController : UIViewController <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *theWebView;

@end

10 Comments

although I just tried it and it still didn't fully work :( although it did get rid of the error
Could the problem be that I use an underscore in my html file build_business ?
I don't think so. Have you verified that the outlet is set? I also suppose the UIWebView object isn't null... Have you tried looking directly inside the bundle in the Simulator to see if the HTML files are actually there?
I did not add that html file specifically to the bundle - should I do that?
Yes. You should do that. But just to make sure you have everything setup, you should test this out by doing (instead of using a file): NSURL *url = [NSURL URLWithString:@"stackoverflow.com"];
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.