gpt4 book ai didi

ios - webViewDidFinishLoad 不工作?

转载 作者:行者123 更新时间:2023-12-01 18:13:23 27 4
gpt4 key购买 nike

在我的应用程序中,我试图在加载 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];
}

最佳答案

嗨,您可能没有设置正确的代表。

这是给你的小代码提示。

-(void)viewDidLoad {

mWebView = [[UIWebView alloc] init];
mWebView.delegate = self;
mWebView.scalesPageToFit = YES;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView {

[loadingImageView removeFromSuperview];
NSLog(@"finish");
}

在你的 .h 文件中添加。
@interface MyView: UIViewController <UIWebViewDelegate> {
UIWebView *webView;
}

代码修复。

对于 .h 文件
@interface ViewController : UIViewController<UIWebViewDelegate>


-(IBAction)makePhoneCall:(id)sender;

@property (nonatomic, strong) IBOutlet UIWebView *webView;
@property(nonatomic, strong) UIImageView *loadingImageView;


@end

对于 .m 文件
- (void)viewDidLoad
{


[super viewDidLoad];

webView.delegate = self;

//**************** 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];

}

关于ios - webViewDidFinishLoad 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26148507/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com