0

我的应用程序是一个简单的新闻应用程序,它包含一个部分按钮。当我们单击左侧的按钮时,它会显示一个包含很多项目(如体育、政治、地区新闻、国际新闻、游戏等)的弹出窗口。当我单击这些项目将从 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)

下图显示了简单的绘图

在此处输入图像描述

放置在滚动视图内的 webview

请检查以下代码

-(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;
         }
    }
}
4

1 回答 1

1

A 的NaN意思是“不是数字”。您有时可能还会看到inf,它代表“无穷大”。当浮点计算导致无穷大或未定义的值时,就会发生这种情况。通常它是除以 0 错误或未初始化变量的结果。这意味着在某些时候,您将 CALayer 的位置设置为无效的浮点值。NaNs您可以通过调用标准 C 宏来检查值isnan(),尽管根据此页面,它不是可移植的。FWIW,我很幸运使用它。(还有一个isinf()用于检查无穷大的宏。)您可能还幸运地使用静态分析器查看是否有任何未初始化的变量。(或者打开未初始化变量的编译器警告,如果它'

于 2013-09-06T03:39:33.943 回答