简体   繁体   中英

UIWebView Not loading

I am having a problem where UrlDisplay isn't displaying any data. UrlDisplay is located at the bottom of my .M. What I am doing is requesting a website collecting a few urls specific to the users request. Then setting up UiWebViews for them to navigate though is there any way to split a single UiWebView, or is this the best way to do it? (My sample is only collecting one website and trying to set one website to a UIWebView)I am not sure of why this is happening Everything in the .h is connected properly to the storyboard. Thanks for the help in advanced for any feed back!

.H

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *UrlDisplay;

@end

.M

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize UrlDisplay;

- (void)viewDidLoad
{
[super viewDidLoad];


NSURL *website = [NSURL URLWithString:@"www.Google.com"];



NSURLRequest *request = [NSURLRequest requestWithURL:website];



NSURLResponse* response = nil;

NSError *error = nil;

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

//storing data in a string

NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSArray *newString = [myString componentsSeparatedByString:@"\n"];
// Do any additional setup after loading the view, typically from a nib.

NSMutableString *curLineNum;

NSString *curLine;

NSMutableArray *URL =[[NSMutableArray alloc]init];

int i;

for (i = 0; i <[newString count]; i++) {

    curLine = [newString objectAtIndex:i];

    if ([curLine rangeOfString:@"Start Here"].location != NSNotFound) {

        NSScanner *scanner = [NSScanner scannerWithString:curLine];

        [scanner scanUpToString:@"Start Here" intoString:NULL];

        [scanner setScanLocation:([scanner scanLocation]) + 16];

        [scanner scanUpToString:@"End Here" intoString:&curLineNum];

        [Url addObject:curLineNum];


    }
}

NSURL *preWebsite = [NSURL URLWithString:[Url objectAtIndex:0]];

NSURLRequest *preRequest = [NSURLRequest requestWithURL:preWebsite];

[UrlDisplay loadRequest:preRequest];
//NSLog(@"%@",myString);

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

the method URLWithString always expecting full URL path including URL scheme. In your case URL scheme is missing. Try this.

NSURL *website = [NSURL URLWithString:@"http://www.Google.com"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM