私のアプリは単純なニュース アプリです。セクション ボタンが含まれています。左側のボタンをクリックすると、多くの項目 (スポーツ、政治、地域ニュース、国際ニュース、ゲームなど) を含むポップオーバーが表示されます。これらのアイテムは、xml からコンテンツをロードし、webview に表示します。
しかし、最大 3 から 4 のようないくつかのアイテムをクリックしようとすると、アプリがクラッシュします。アプリがクラッシュするのは iPad 1 (iOS 5.1) と iPad 3 (iOS6.1.3) でのみです。シミュレーターでアプリを実行すると、クラッシュ ログが表示されます。
クラッシュログ
*** 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)
次の図は簡単な図を示しています
スクロール ビュー内に配置された Web ビュー
以下のコードを確認してください
-(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;
}
}
}