2013-04-04 46 views
0

我正試圖加載一個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 

回答

1

你有沒有設置webView委託?沒有設置,你的webViewDidFinishLoad:方法將永遠不會觸發。

webView.delegate = self; 
+0

我在哪裏設置呢? – sharataka 2013-04-04 21:46:13

+0

你的viewDidLoad就在你調用loadRequest之前: – Bartu 2013-04-04 21:48:30

+0

它似乎沒有工作,我也得到一個警告(語義問題)。 – sharataka 2013-04-04 21:51:36

4

試試這個,

@interface ViewController() <UIWebViewDelegate> 

{ 
    UIWebView * webView; 
    UIImageView * imageView; 
} 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    imageview = [[UIImageView alloc]init]; 
    [imageview setFrame:CGRectMake(0.0, 0.0, 320.0, 460.0)]; 
    [imageview setImage:[UIImage imageNamed:@"Red.png"]]; 
    [self.view addSubview:imageview]; 

    webView = [[UIWebView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 460.0)]; 
    [webView setDelegate:self]; 
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]]; 

    // Do any additional setup after loading the view, typically from a nib. 
} 

// UIWebView Delegate 

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    [imageView removeFromSuperview]; 
    [self.view addSubview:webView]; 
} 

@end 
0

你爲什麼不直接添加啓動圖像到您的.plist文件

相關問題