Undeclared delegate and shouldStartLoadWithRequest

2019-09-02 10:10发布

i am newer to coding in general! I am trying to create a webview that doesnt allow navigation to viewers. I have most of the coding typed up, but i have two undeclared errors and i am not sure how to solve this issue.

What i am trying to do is create a webView, but i would like to make it where the viewer of the webView cant navigate to other pages. If he/she does attempt too it does not fulfill the request.So basically it stays specifically on one page.

If i just need declare them in a really simple way then please show me and help. Thank you.

The Errors are shown below:

#import "ViewController.h"

@interface ViewController()
<UIWebViewDelegate>

@end

@implementation ViewController
@synthesize webView;

- (void)viewDidLoad
{
[super viewDidLoad];
webview:delegate = nil;
NSURL *url = [NSURL URLWithString:@"https://twitter.com/u_bett"];
NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlrequest];

}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request         navigationType:(UIWebViewNavigationType)navigationType
{
return NO;
}

1条回答
ら.Afraid
2楼-- · 2019-09-02 10:20

Your method contains lot of issues:

Change that like:

- (void)viewDidLoad
{
    [super viewDidLoad];
    webview.delegate = self;  
    NSURL *url = [NSURL URLWithString:@"https://twitter.com/u_bett"];    
    NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url];
    [webView loadRequest:urlrequest];

}

And implement shouldStartLoadWithRequest: like:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if(navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        return NO;
    }
    return YES;
}

Check this tutorial for UIWebView implementation. I would like to suggest you to learn Objective C thoroughly before starting the development. (Some investment at this point will help you to save a lot of time in future)

查看更多
登录 后发表回答