My app is a simple news app,It contains a sections button .When we click the button on leftside it will show up a popover with lots of items (like sports,politics,regional news,international news, games etc.) When i click these items it will will load the contents from xml and display to a webview.
But wen i tried to click some items like maximum 3 to 4 continueusly the app is crashing. app crashing only in ipad 1(iOS 5.1) and in ipad 3 its working fine (iOS6.1.3). I got the crash log when i run the app in simulator .
CRASH LOGS
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(0x236e022 0x1802cd6 0x2316a48 0x23169b9 0x7c5c0d 0x7bbf55 0x1a227d3 0xb03fae 0xd0eff3 0xb0307e 0x236fdea 0x22d97f1 0x9be27d 0x9aa9ae 0x9bc86f 0x9ab70f 0x9abd07 0x10aa7 0x9f65c5 0x9f67fa 0x128b85d 0x2342936 0x23423d7 0x22a5790 0x22a4d84 0x22a4c9b 0x1dfb7d8 0x1dfb88a 0x965626 0x22cd 0x21f5)
terminate called throwing an exception(lldb)
following drawing shows the simple drawing
the webview placed inside a scroll view
Please check the following codes
-(void)loadpages:(int)page{
if((page>links.count-1)||(page<0))
return;
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL fileURLWithPath:HTMLPath]];
if(([[[[[scrollView subviews] objectAtIndex:page] request] URL] absoluteString] ==nil)||(page==0)||(page==31))
{
[[[self.scrollView subviews] objectAtIndex:page] loadRequest:request];
}else if([[[[[[scrollView subviews] objectAtIndex:page] request] URL] absoluteString] isEqualToString:@"about:blank"]){
[[[self.scrollView subviews] objectAtIndex:page] loadRequest:request];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)sender {
if (sender==scrollView) {
// Update the page when more than 50% of the previous/next page is visible
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
if(currentPage!= page){
currentPage = page;
// NSLog(@"currentpage:%d",currentPage);
NSDictionary * news = (NSDictionary *)[links objectAtIndex:page];
if (page==0) {
Title_buttonItem.hidden=NO;
[Title_lbl setText:nil];
[Title_buttonItem setTitle:nil forState:UIControlStateNormal];
[Title_buttonItem setImage:[UIImage imageNamed:@"Logo1.png"] forState:UIControlStateNormal];
}else{
[Title_lbl setText:[news objectForKey:@"title"]];
Title_buttonItem.hidden=YES;
}
if (_lastContentOffset < (int)sender.contentOffset.x) {
// moved right
if (currentPage==31) {
TwoPage=currentPage;
allpage=0;
[self loadpages:currentPage];
} else {
TwoPage=currentPage;
allpage=0;
[self loadpages:currentPage];
[self loadpages:currentPage+1];
}
}
else {
// moved left
TwoPage=0;
if (currentPage==0) {
allpage=currentPage;
[self loadpages:currentPage];
}else{
allpage=currentPage;
[self loadpages:currentPage];
[self loadpages:currentPage-1];
}
}
if ([Checking_DistrictPage isEqualToString:@"YES"]) {
if (currentPage<([Title_Sections count]-[Title_Districts count])) {
frame.origin.x = (self.scrollView.frame.size.width) * MovePage;
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [links count],self.scrollView.frame.size.height);
[scrollView scrollRectToVisible:CGRectMake(([Title_Sections count]-[Title_Districts count])*scrollView.frame.size.width, 0, scrollView.frame.size.width, scrollView.frame.size.height) animated:NO];
//[[[self.scrollView subviews] objectAtIndex:page] loadRequest:request];
}else{
frame.origin.x = (self.scrollView.frame.size.width) * MovePage;
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [links count],self.scrollView.frame.size.height);
// if (Check_district==YES) {
// splashImage =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
// [splashImage setImage:[UIImage imageNamed:@"Default-Landscape.png"]];
// [self.tabBarController.view addSubview:splashImage];
// [act startAnimating];
// [splashImage addSubview:act];
// timer=[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(RemovingSplash) userInfo:nil repeats:NO];
// [self startDistrictfeedstore];
//
// }
}
}
else{
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL fileURLWithPath:HTMLPath]];
[[[self.scrollView subviews] objectAtIndex:page] loadRequest:request];
}
}
}
//NSLog(@"scrollview did scroll");
}
- (BOOL)webView:(UIWebView *)webView1 shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if (webView1==AD_webview) {
}else{
NSString *requestString = [[request URL] absoluteString];
if ([requestString hasPrefix:@"mb::"])
{
NSArray *components = [requestString componentsSeparatedByString:@"::"];
NSString *functionCall = [[[components objectAtIndex:1] componentsSeparatedByString:@"****"] objectAtIndex:0];
NSString *args = [[[components objectAtIndex:1] componentsSeparatedByString:@"****"] objectAtIndex:1];
args = [args stringByReplacingOccurrencesOfString:@"$" withString:@"'"];
args = [args stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[NSNotificationCenter defaultCenter] postNotificationName:functionCall object:args];
return NO;
}
}
}