Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 滚动视图代理方法应用程序正在崩溃_Iphone_Uiscrollview - Fatal编程技术网

Iphone 滚动视图代理方法应用程序正在崩溃

Iphone 滚动视图代理方法应用程序正在崩溃,iphone,uiscrollview,Iphone,Uiscrollview,如果我水平移动滚动视图,它必须显示新表,其中有新标签,每次一个问题。问题的数量可能是10或20。这意味着每次滚动视图水平移动时,我们都必须创建新表和新标签 当用户第一次选择委托方法将调用的类别时。在此方法中,我还创建了表视图和标签,如下所示 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ { @试一试{ cancelScroll = NO; if (scrollEnabled) { scrollEnab

如果我水平移动滚动视图,它必须显示新表,其中有新标签,每次一个问题。问题的数量可能是10或20。这意味着每次滚动视图水平移动时,我们都必须创建新表和新标签

当用户第一次选择委托方法将调用的类别时。在此方法中,我还创建了表视图和标签,如下所示

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
{ @试一试{

cancelScroll = NO;

if (scrollEnabled) {

    scrollEnabled = NO;
NSLog(@"Begin Scroll Dragging");
NSLog(@"%f -- %f",scrollView.contentOffset.x,scrollView.contentOffset.y);

if (scrollDirection == 1) {

    scrollDirection = 0;

    CGRect rect = mainTable.frame;
    [scrollTableView scrollRectToVisible:rect animated:NO];
    return;
}

else if (scrollDirection == 2) {

    scrollDirection = 0;
    HUDProgress.alpha=0;

    CGFloat pageWidth = scrollTableView.frame.size.width;
    int page;
    if (pageControlBeingUsed) {

        page = pageControl.currentPage;
     //   pageControlBeingUsed = NO;

    }

    else {

        page= floor((scrollTableView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    }

    NSLog(@"%d",page);

    if (page == [questionTextArray count] - 1) {

        if (maxValueReached) {

            CGRect rect = mainTable.frame;
            [scrollTableView scrollRectToVisible:rect animated:NO];
            return;
        }

    }

    photoAlbumView.alpha = 0;
    photoView.alpha = 0;
    FileAddView.alpha = 0;
    settingsView.alpha = 0;
    refreshView.alpha = 0;

    photoAlbumViewPortrait.alpha = 0;
    FileAddViewPortrait.alpha = 0;
    settingsViewPortrait.alpha = 0;
    refreshViewPortrait.alpha = 0;

    checkValueForTableView = TRUE;


    if (orientation == 1 ) {

        if (!expandAction) {

            scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 720.0, 596.0);

        }
        else {

            scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 930.0, 596.0);

        }
    }
    else {
        if (!expandAction) {

            scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 520.0, 680.0);

        }
        else {

            scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 720.0, 680.0);

        }

    }


    if (page >= 0) {

        if (page > tempPage) {

            int difference = page - tempPage;

            NSLog(@"%d",difference);
            NSLog(@"%f",tableXPosition);

            tableXPosition =  (tableXPosition  + (difference * tableWidthPosition));
            NSLog(@"%f",tableXPosition);
        }

        else if (page < tempPage){

            int difference = tempPage - page;

            NSLog(@"%d",difference);

            tableXPosition = abs ((difference * tableWidthPosition) - tableXPosition);

            NSLog(@"%f",tableXPosition);

        }

        else {

            CGRect rect = mainTable.frame;
            [scrollTableView scrollRectToVisible:rect animated:NO];

        }

    }

    if([questionTextArray count] > 1)
    {
        pageControl.numberOfPages = [questionTextArray count];

        [pageControl addTarget:self action:@selector(changePage) forControlEvents:UIControlEventValueChanged];

        if(scrollTableView != nil)
        {
            if (mainTable != nil) {

                [mainTable release];
                mainTable = [[UITableView alloc] initWithFrame:CGRectMake(tableXPosition , 45.0, tableWidthPosition, 565.0) style:UITableViewStyleGrouped];
            }

            mainTable.delegate = self;
            mainTable.dataSource = self;
            mainTable.scrollEnabled = YES;
            mainTable.backgroundColor = [UIColor clearColor];
            [mainTable reloadData];
            [scrollTableView addSubview:mainTable];

        }

        NSLog(@"%d  %d",page,previousPage);

        if (page >= 0) {

            if (previousPage != page) {

                pageControl.currentPage= page;
            }
        }


        if (page >= 0) {

            if (previousPage != page) {

                UIImageView *imgView = [[UIImageView alloc] init];
                UILabel *questionTextLbl1 = [[UILabel alloc] init];
                UILabel *questionNumberLbl1 = [[UILabel alloc] init];

                if (orientation == 1) {
                      if (!expandAction) {

                        imgView.frame = CGRectMake(tableXPosition, 0.0, 710.0, 39.0);
                        questionTextLbl1.frame =  CGRectMake(10.0, 2.0, 430.0, 35.0);
                        questionNumberLbl1.frame = CGRectMake(550.0, 2.0, 200.0, 35.0);
                    }
                    else {

                        imgView.frame = CGRectMake(tableXPosition, 0.0, 920.0, 39.0);
                        questionTextLbl1.frame =  CGRectMake(50.0, 2.0, 500.0, 35.0);
                        questionNumberLbl1.frame = CGRectMake(800.0, 2.0, 150.0, 35.0);

                        compressButton = [UIButton buttonWithType:UIButtonTypeCustom];
                        compressButton.frame = CGRectMake(10.0, 10.0, 25.0, 25.0);
                        [compressButton setImage:[UIImage imageNamed:@"Drop Down small2.png"] forState:UIControlStateNormal];
                        [compressButton addTarget:self action:@selector(compressAction) forControlEvents:UIControlEventTouchUpInside];


                    }


                    imgView.contentMode = UIViewContentModeScaleToFill;
                    imgView.backgroundColor = [UIColor clearColor];
                    imgView.image = [UIImage imageNamed:@"Top gary header.png"];
                    [scrollTableView addSubview:imgView];
                    if (!expandAction) {


                    }
                    else {
                        compressButton.backgroundColor = [UIColor clearColor];
                        [compressButton addTarget:self action:@selector(compressAction) forControlEvents:UIControlEventTouchUpInside];
                      [imgView addSubview:compressButton];
                        imgView.userInteractionEnabled = YES;

                    }

                    questionTextLbl1.backgroundColor = [UIColor clearColor];
                    questionTextLbl1.numberOfLines = 0;
                    questionTextLbl1.text = [NSString stringWithFormat:@"%d.%@?",page + 1,[questionTextArray objectAtIndex:page]];
                    NSLog(@"Question arry %@", questionTextArray);
                    [imgView addSubview:questionTextLbl1];

                    if([questionTextArray count] > 1)
                    {
                        questionNumberLbl1.text = [NSString stringWithFormat:@"Question %d/%d",page + 1,[questionTextArray count]];

                    }
                    else {
                        questionNumberLbl1.text = [NSString stringWithFormat:@"Question 1"];
                    }

                    questionNumberLbl1.backgroundColor = [UIColor clearColor];
                    questionNumberLbl1.numberOfLines = 0;
                    [imgView addSubview:questionNumberLbl1];
                }

                else {

                    if (!expandAction) {

                        imgView.frame = CGRectMake(tableXPosition, 0.0, 530.0, 38.0);
                        questionTextLbl1.frame =  CGRectMake(10.0, 2.0, 350.0, 35.0);
                        questionNumberLbl1.frame = CGRectMake(380.0, 2.0, 150.0, 35.0);
                    }
                    else {
                        imgView.frame = CGRectMake(tableXPosition, 0.0, 720.0, 38.0);
                        questionTextLbl1.frame =  CGRectMake(40.0, 2.0, 500.0, 35.0);
                        questionNumberLbl1.frame = CGRectMake(550.0, 2.0, 150.0, 35.0);

                        compressButton = [UIButton buttonWithType:UIButtonTypeCustom];
                        compressButton.frame = CGRectMake(10.0, 10.0, 25.0, 25.0);
                        [compressButton setImage:[UIImage imageNamed:@"Drop Down small2.png"] forState:UIControlStateNormal];
                        [compressButton addTarget:self action:@selector(compressAction) forControlEvents:UIControlEventTouchUpInside];

                    }

                    imgView.contentMode = UIViewContentModeScaleToFill;
                    imgView.backgroundColor = [UIColor clearColor];
                    imgView.image = [UIImage imageNamed:@"Top gary header.png"];
                    [scrollTableView addSubview:imgView];

                    if (!expandAction) {

                    }
                    else {
                    [imgView addSubview:compressButton];
                    imgView.userInteractionEnabled = YES;

                    }


                    questionTextLbl1.backgroundColor = [UIColor clearColor];
                    questionTextLbl1.numberOfLines = 0;
                    questionTextLbl1.font = [UIFont systemFontOfSize:14.0];
                    questionTextLbl1.text = [NSString stringWithFormat:@"%d.%@?",page + 1,[questionTextArray objectAtIndex:page]];
                    NSLog(@"Question arry %@", questionTextArray);
                    [imgView addSubview:questionTextLbl1];

                    if([questionTextArray count] > 1)
                    {
                        questionNumberLbl1.text = [NSString stringWithFormat:@"Question %d/%d",page + 1,[questionTextArray count]];

                    }
                    else {
                        questionNumberLbl1.text = [NSString stringWithFormat:@"Question 1"];
                    }

                    questionNumberLbl1.backgroundColor = [UIColor clearColor];
                    questionNumberLbl1.numberOfLines = 0;
                    [imgView addSubview:questionNumberLbl1];

        }

                [mainTable reloadData];
           //     [scrollTableView  addSubview:mainTable];

                [imgView release];
                [questionNumberLbl1 release];
                [questionTextLbl1 release];
}

} @捕获(NSException*异常){

} 它在模拟器中运行良好,但在iPad中有一段时间它在滚动时运行良好

滚动15或20次后,它将崩溃


有时使用仪器运行时,崩溃日志也不显示任何内容,有时显示内存警告。

如果显示崩溃日志就可以。.有时使用仪器运行时,崩溃日志也不显示任何内容,有时显示内存警告。.它在哪里显示内存警告?根据你在这里所描述的,我认为你消耗了太多的内存。同时粘贴来自if外部的代码。当在ScrollViewDiEndDeclaring中水平滚动时,此时仅执行Declaring方法。但是,当同时使用仪器运行时,它有时仅在崩溃日志中显示。例如,“内存警告”…但应用程序在没有显示此警告的情况下崩溃,有时在使用仪器运行时也在同一个位置。我清除了所有泄漏。没有泄漏。我用的是iPad1,内存非常少,iPad1内存有什么问题吗。。
                if (pageControlBeingUsed) {

                    [scrollTableView scrollRectToVisible:rect animated:YES];
                    pageControlBeingUsed = NO;

                }

                else {

                    [scrollTableView scrollRectToVisible:rect animated:NO];
                }

                tempPage = page;
                previousPage = page;

                if (page == [questionTextArray count] - 1){

                    maxValueReached = YES;
                }

                else {

                    maxValueReached = NO;
                }
            }

        }

        NSLog(@"page:%d  previous page:%d temp page:%d",page,previousPage,tempPage);
  //      sleep(0);

    }

}
else {

    [self killScroll];
    scrollDirection = 0;

}
    NSLog(@"Exception: %@---%@",[exception name],[exception reason]);
}
@finally {

    NSLog(@"Finally block");
}