Reputation: 308
I have a UIWebView
that is successfully being created dynamically from an included class file (I think... there are no errors being spit out). My function that creates this webview in the Foo.m
class file is:
+(void) openWebView {
dispatch_async(dispatch_get_main_queue(), ^{
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 16, 16)];
[webView setDelegate:self];
[webView setHidden:YES];
NSURL *url = [NSURL URLWithString:address];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
NSLog(@"Successful web open: ", url);
});
}
I do get a warning error message on the setDelegate
line (it doesn't crash the app though) that reads:
Incompatible pointer types sending 'const Class' to parameter of type 'id:<UIWebViewDelegate>'
The problem is that while the NSLog
does log the correct URL it is trying to open, the page actually never gets called (I can tell this because I have a PHP counter on that page that increments each time it is opened).
So my questions are:
self
references to. It was also made mention here in my precursor question to this one.loadRequest
Sorry everyone, as you probably can figure out from my questions, Obj-C is a little new to me, but I am really struggling here and would appreciate the help! Thanks.
Upvotes: 1
Views: 1036
Reputation: 154533
Your openWebView
method is a class method because of the +
at the beginning. For this reason, you don't have an object. self
in this case returns the class (hence the warning). Perhaps you want openWebView
to be an instance method, so change the +
to -
and then self
will point to your instantiated object.
To check if the loadRequest worked, you implement the UIWebViewDelegate
delegate methods webViewDidStartLoad
and webViewDidFinishLoad
in your delegate (ie Foo.m) and see if they get called.
Upvotes: 1
Reputation: 40211
You are implementing a class method (indicated by the +
sign). self
in a class method refers to the class itself, not an instance. The delegate
of a UIWebView
(or anything really) has to be an object though.
Upvotes: 1