我正試圖加載一個UIWebView只有在頁面加載後。在頁面準備就緒之前,我只想要顯示啓動畫面。我試着按照這個頁面上的第一個答案(XCode Prevent UIWebView flashing white screen after Launch Image),但它似乎不工作...啓動屏幕加載和UIWebView從不加載。如何在應用程序啓動後纔會在頁面加載後顯示UIWebView?
有什麼建議嗎?
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
IBOutlet UIWebView *webView;
}
@property (nonatomic, retain) IBOutlet UIWebView *webview;
@property(nonatomic, strong) UIImageView *loadingImageView;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController;
@synthesize webview;
@synthesize loadingImageView;
- (void)viewDidLoad
{
[super viewDidLoad];
//**************** Set website URL for UIWebView
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://http://warm-chamber-7399.herokuapp.com/"] cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0]];
//**************** Add Static loading image to prevent white "flash" ****************/
UIImage *loadingImage = [UIImage imageNamed:@"Default.png"];
loadingImageView = [[UIImageView alloc] initWithImage:loadingImage];
loadingImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Default.png"],
nil];
[self.view addSubview:loadingImageView];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Remove loading image from view
[loadingImageView removeFromSuperview];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我在哪裏設置呢? – sharataka 2013-04-04 21:46:13
你的viewDidLoad就在你調用loadRequest之前: – Bartu 2013-04-04 21:48:30
它似乎沒有工作,我也得到一個警告(語義問題)。 – sharataka 2013-04-04 21:51:36