0

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;
}
  • What are you trying to do ? `webview.delegate = nil;` and the other one is completely wrong, you can't call a method like that. – Midhun MP Dec 04 '13 at 16:27
  • What i am trying to do is obviously create a webView, but i would like to make it where the viewer of the webView cant navigate to other pages. If he does attempt too it does not fulfill the request.So basically it stays specifically on one page. – BettByteSquad Dec 04 '13 at 16:29

1 Answers1

2

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)

Midhun MP
  • 103,496
  • 31
  • 153
  • 200