我在使用 UIWebView 时遇到了一些问题。我在 Interface Builder 中创建了我的 UIWebView,并创建了一个 socket 作为 tasksWebView。我还将它作为委托(delegate)链接到我的 View Controller 。我要加载 http://www.taskyo.com ,但是当我尝试加载它时,我只得到一个白页。它在 Mobile Safari 中运行良好,所以我对问题出在哪里感到困惑。更令人困惑的是,当我替换 http://www.taskyo.com 时与 http://www.google.com ,它工作正常。如果我尝试访问 http://www.taskyo.com通过谷歌,当我点击 URL 时,我得到一个白页。我的代码如下:
头文件
#import <UIKit/UIKit.h>
@interface AppThirdViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *tasksWebView;
- (IBAction)goBack:(id)sender;
- (IBAction)goHome:(id)sender;
@end
执行文件
#import "AppThirdViewController.h"
@interface AppThirdViewController ()
@end
@implementation AppThirdViewController
@synthesize tasksWebView = _tasksWebView;
- (void)viewDidLoad
{
[super viewDidLoad];
[self goHome:self];
}
- (void)viewDidUnload
{
[super viewDidUnload];
_tasksWebView = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)goBack:(id)sender
{
[_tasksWebView goBack];
}
- (IBAction)goHome:(id)sender
{
NSURL *tasksURL = [NSURL URLWithString:@"http:/www.taskyo.com/"];
NSURLRequest *tasksRequest = [NSURLRequest requestWithURL:tasksURL];
[_tasksWebView loadRequest:tasksRequest];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Error : %@",error);
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"Started to load!");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@"Finished loading!");
}
@end
在我的控制台中,我得到以下输出:
Started to load
Finished loading!
有人对这个问题有任何想法吗? 提前致谢。
编辑:已修复 - 请参阅下面的回答。
最佳答案
在撰写此答案时,Taskyo.com 不可用。 (即使我的网络浏览器也无法打开您提供的链接)。
关于iphone - UIWebView 不会加载某些网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10932894/