关于WKWebView加载完毕的代理方法

iOS 码拜 8年前 (2016-05-09) 2856次浏览
现在在做一个项目,首页是原生的,然后页面上有10个左右的button,点击链接H5页面;
需求:在点击button的时候,当前页面出现loading动画,在H5页面加载完毕后跳转
本人的思路:在button action的方法中,只是alloc init一个H5页面,在H5页面加载完毕的代理方法中发出Notification,然后在首页添加监听Notification,push页面.
button action的代码:
self.aniCoverView.hidden = NO;
self.gifView.image = [UIImage sd_animatedGIFNamed:@”aniGif”];
[YKBNotificationCenter addObserver:self selector:@selector(closeAnimation:) name:YKBCloseAniNotification object:nil];
hotelVC = nil;
hotelVC = [[YNHotelController alloc] init];
H5页面中加载完毕发送的Notification:
[YKBNotificationCenter postNotificationName:YKBCloseAniNotification object:nil userInfo:@{YKBURLString : self.urlString}];
首页监听Notification的方法:
NSString * tempString = notifi.userInfo[YKBURLString];
if ([tempString containsString:@”Flight/Search/”]) {
jiPiaoVC.hidesBottomBarWhenPushed = YES;
[self.tabBarController.parentViewController.navigationController pushViewController:jiPiaoVC animated:YES];
[YKBNotificationCenter removeObserver:self name:YKBCloseAniNotification object:nil];
}
现在有个问题:在跳转后页面会先白屏,然后才出现H5页面内容,怎么才能避过白屏,直接显示H5页面呢?跪求各路高手指点
解决方案

20

hotelVC = [[YNHotelController alloc] init];
你只是把这个vc创建出来,没有调用他的view,这样的话是不会执行到viewDidLoad这个方法的,本人估计你大部份的加载动作都是放在这个方法,或生命周期在这个方法之后的其他方法里
你可以设置断点看看
解决的办法其实挺土的
你再后面加一句
hotelVC.view;这样就可以了(编译器会有黄色的警告,可以不管他)

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于WKWebView加载完毕的代理方法
喜欢 (0)
[1034331897@qq.com]
分享 (0)