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