我对UIWebView有点问题。我在Interface Builder中创建了我的UIWebView,并创建了一个作为tasksWebView的插座。我还将它作为代理与我的View Controller联系起来。我想加载http://www.taskyo.com,但是当我尝试加载它时,我只是得到一个白页。它在Mobile Safari中运行良好,所以我很困惑问题在哪里。为了让它更令人困惑,当我用http://www.google.com代替http://www.taskyo.com时,它工作正常。如果我尝试通过Google访问http://www.taskyo.com,则当我点击该网址时,我会看到一个白页。我的代码如下:UIWebView不会加载某些网站
头文件
#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!
有没有人有任何想法,解决问题? 在此先感谢。
编辑:固定 - 请参阅下面的答案。
您是否尝试过其他网页,例如www.google.com?我可以在没有任何问题的情况下加载并在UIWebView中显示您的页面。因此,看看你如何显示视图控制器。 – Gruntcakes
+1,很好的问题。 – 2012-06-07 14:19:18
我把你的代码粘贴到一个简单的测试应用程序,并加载模拟器和设备的页面。如果其他页面为您加载,我不知道该说什么....您是否正在浏览缓存服务器? –