【问题标题】:How to show a UIWebView after app launch only after the page loads?仅在页面加载后,如何在应用启动后显示 UIWebView?
【发布时间】:2013-03-27 03:34:57
【问题描述】:

我试图仅在页面加载后加载 UIWebView。在页面准备好之前,我只希望显示启动画面。我尝试遵循此页面上的第一个答案(XCode Prevent UIWebView flashing white screen after Launch Image),但它似乎不起作用......启动画面加载并且 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

【问题讨论】:

    标签: iphone objective-c xcode ios4


    【解决方案1】:

    试试这个,

    @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
    

    【讨论】:

      【解决方案2】:

      为什么不直接将启动图像添加到 .plist 文件中

      【讨论】:

        【解决方案3】:

        你设置webView的代理了吗?如果不进行设置,您的 webViewDidFinishLoad: 方法将永远不会触发。

        webView.delegate = self;
        

        【讨论】:

        • 在您调用 loadRequest 之前的 viewDidLoad:
        • 它似乎不起作用,我也收到警告(语义问题)。
        • 在您的 ViewController.h 中,将 @interface ViewController : UIViewController{ 更改为 @interface ViewController : UIViewController &lt;UIWebViewDelegate&gt; {
        • 嗯,它仍然无法正常工作。它仍然停留在初始屏幕上。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-02
        • 2013-05-13
        • 1970-01-01
        • 2018-07-16
        相关资源
        最近更新 更多