在我第一次加载URL
时,它运行正常,但在我加载新URL
之后,应用程序崩溃了。我的类是UIView
的子类。
@implementation web
{
UIWebView * wv;
BOOL isGoogle;
UIImageView *iview;
}
- (id)initWithFrame:(CGRect)frame loadWithUrl:(NSString *)url
{
self = [super initWithFrame:frame];
if (self) {
wv = [[UIWebView alloc] initWithFrame:frame];
wv.delegate = self;
developerUrl = url;
[wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
[self addSubview:wv];
}
return self;
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString * url = [[request URL] absoluteString];
if ([url hasPrefix:@"https://google.com"])
{
isGoogle = true;
NSArray * images = [[NSArray alloc] initWithObjects:[ UIImage imageNamed:@"1.tiff"],[ UIImage imageNamed:@"2.tiff"],[ UIImage imageNamed:@"3.tiff"],[ UIImage imageNamed:@"4.tiff"],[ UIImage imageNamed:@"5.tiff"],[ UIImage imageNamed:@"6.tiff"],[ UIImage imageNamed:@"7.tiff"],[ UIImage imageNamed:@"8.tiff"],[ UIImage imageNamed:@"9.tiff"],[ UIImage imageNamed:@"10.tiff"], nil];
iview = [[UIImageView alloc] initWithFrame:self.frame];
iview.animationImages = images;
[iview startAnimating];
[self addSubview:iview];
}
return true;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
if (isGoogle)
{
NSString * content = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
[wv stringByEvaluatingJavaScriptFromString :@"document.open();document.close()"];
NSData * data = [content dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSDictionary * jsonDict = json;
NSDictionary * dict = [jsonDict objectForKey:@"RESULT"];
NSDictionary * dict2;
if ([dict objectForKey:@"ERROR"])
{
UIAlertView * aview = [[UIAlertView alloc] initWithTitle:@"unknown error" message:nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[aview show];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[iview removeFromSuperview];
if([wv isLoading])
{
[wv stopLoading];
}
[wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://yahoo.com"]]]
//APP CRASHES HERE......
}
/
*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
`