【发布时间】:2014-10-01 18:52:22
【问题描述】:
在我的应用程序中,我试图在加载 UIWebView 时显示初始图像,因此它不仅仅是一个空白屏幕。但是我的 webViewDidFinishLoad 方法不起作用。这意味着一旦 UIWebView 加载,启动图像就会出现,但不会从屏幕上消失。
我的方法代码是:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"content loading finished");
[loadingImageView removeFromSuperview];
}
任何关于为什么该方法不起作用的帮助将不胜感激。
我的.h:
@interface ViewController : UIViewController
-(IBAction)makePhoneCall:(id)sender;
@property (nonatomic, strong) IBOutlet UIWebView *webView;
@property(nonatomic, strong) UIImageView *loadingImageView;
@end
我的 ViewDidLoad 和 webViewDidFinishLoading:
- (void)viewDidLoad {
UIWebView *mWebView = [[UIWebView alloc] init];
mWebView.delegate = self;
mWebView.scalesPageToFit = YES;
[super viewDidLoad];
}
//**************** Set website URL for UIWebView
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.sleafordpizza.com/food"]]];
//**************** Add Static loading image to prevent white "flash" ****************/
UIImage *loadingImage = [UIImage imageNamed:@"LittleItalyLogo.png"];
loadingImageView = [[UIImageView alloc] initWithImage:loadingImage];
loadingImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"LittleItalyLogo.png"],
nil];
[self.view addSubview:loadingImageView];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"content loading finished");
// Remove loading image from view
[loadingImageView removeFromSuperview];
}
【问题讨论】:
-
您是否设置了网络视图的
delegate?