- (IBAction)saveButton:(id)sender
{
NSURL *yourURL = [NSURL URLWithString: webpageURLLabel.text ];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:yourURL];
if ([self checkURL] == YES) {
[webpagePreview loadRequest:request];
webpagePreview.scalesPageToFit = YES;
}
}
- (BOOL)checkURL
{
NSString *arrayOfStrings = [NSArray arrayWithObjects:@"http://", @"https://", nil];
NSString *stringToSearchWithin = webpageURLLabel.text;
BOOL found=NO;
for (NSString *s in arrayOfStrings)
{
if ([stringToSearchWithin rangeOfString:s].location != NSNotFound)
{
found = YES;
break;
} else
{
webpageURLLabel.text = [NSString stringWithFormat:@"http://%@", webpageURLLabel.text];
found = YES;
break;
}
}
return found;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
webpageTitleLabel.text = [webpagePreview stringByEvaluatingJavaScriptFromString:@"document.title"];
}
我調試了它,它看起來像是假設加載。但出於某種原因,當您第一次點擊按鈕時,什麼也沒有發生。iOS網頁無法加載,除非按鈕被點擊兩次
如果用戶第二次點擊按鈕,它可以正常工作。有什麼建議麼?
謝謝。我錯過了。 – 2012-07-28 21:40:30