gpt4 book ai didi

iphone - UIWebView 未加载

转载 作者:行者123 更新时间:2023-11-29 13:02:42 25 4
gpt4 key购买 nike

我遇到了 UrlDisplay 没有显示任何数据的问题。 UrlDisplay 位于我的 .M. 的底部。我正在做的是请求一个网站收集一些特定于用户请求的 url。然后为他们设置 UiWebViews 以进行导航,尽管有什么方法可以拆分单个 UiWebView,或者这是最好的方法吗? (我的示例只收集一个网站并尝试将一个网站设置为 UIWebView)我不确定为什么会发生这种情况。.h 中的所有内容都正确连接到 Storyboard。感谢您提前提供任何反馈的帮助!

.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

最佳答案

URLWithString 方法始终需要包含 URL 方案的完整 URL 路径。在您的情况下,缺少 URL 方案。尝试这个。

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

关于iphone - UIWebView 未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19412162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com