内容是GridView中的随机播放

时间:2013-09-17 03:45:59

标签: iphone ios objective-c xcode gridview

我是IOS开发的新手。我正在使用自定义GridView加载我的项目中的内容,当内容重新加载时,它适用于模拟器。但是在iPad中,内容在重新加载时会被洗牌。

  - (void)reloadData {
        if (_gridViewDelegate && self.superview != nil) {
            CGFloat maxX = 0.f;
            CGFloat maxY = 0.f;
            _scrollView.pagingEnabled = YES;
            self.gridRects = [self.gridViewDelegate rectsForCellsInGridView:self];
            [self.gridCells.allValues makeObjectsPerformSelector:@selector(removeFromSuperview)];
            [self.reuseableCells addObjectsFromArray:self.gridCells.allValues];
            [self.gridCells removeAllObjects];

            for (NSValue *rectValue in self.gridRects) {
                CGRect rect = [rectValue CGRectValue];
                maxX = MAX(maxX, rect.origin.x + rect.size.width);
                maxY = MAX(maxY, rect.origin.y + rect.size.height);


            }
            CGFloat pageWidth = self.scrollView.frame.size.width;
            self.maximumContentWidth=maxX;
            maxX = MAX(MIN(maxX, self.maximumContentWidth), self.contentSize.width);
            maxY = MAX(MIN(maxX, self.maximumContentHeight), self.contentSize.height);
            maxX=pageCount*pageWidth;          
            self.scrollView.contentSize = CGSizeMake(maxX, maxY);
            [self loadCellsInRect:self.visibleRect];
            [self updateStickyViewsPosition];
            [pageNumberLable removeFromSuperview];          
            currentPage = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

            if(pageWidth == 1024)
            {

                pageNumberLable=[[UILabel alloc]initWithFrame:CGRectMake(self.scrollView.contentOffset.x+990, 690, 20, 20)];
                pageNumberLable.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
            }
            else
            {
                 pageNumberLable=[[UILabel alloc]initWithFrame:CGRectMake(self.scrollView.contentOffset.x+740, 943, 20, 20)];
                pageNumberLable.backgroundColor=[UIColor redColor];
                pageNumberLable.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

            }

            pageNumberLable.text=[NSString stringWithFormat:@"%d",currentPage+1];
            pageNumberLable.textColor=[UIColor blackColor];
            pageNumberLable.font = [UIFont boldSystemFontOfSize:16];
            pageNumberLable.backgroundColor=[UIColor clearColor];
            [self.scrollView addSubview:pageNumberLable]; 
            pageIndex = [NSUserDefaults standardUserDefaults];            
            [pageIndex setInteger:currentPage+1 forKey:@"integerKey"];         
        }    
    }

        -(void)reloadGrid
        {
            if(rotate == newIntValue)
            {
                [spinningLibrary stopAnimating];
                [update removeFromSuperview];
                settingLabel.hidden=YES;
                spinningLibrary.hidden=YES;
            }

            if(rotate<newIntValue)
            {
                rotate++;
                [self.gridView scrollRectToVisible:CGRectMake(768*rotate, 0, self.gridView.frame.size.width, self.gridView.frame.size.height) animated:YES];
                [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(reloadGrid123) userInfo:nil repeats:NO];

            }
            [NSThread sleepForTimeInterval:0.2];
            self.gridView.scrollView.hidden=NO;
            [settingsPopoverController dismissPopoverAnimated:YES];

        }

1 个答案:

答案 0 :(得分:2)

你正在比较iPad的RAM和机器的RAM。虽然这不公平。

[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(reloadGrid123) userInfo:nil repeats:NO];

尝试通过设置scheduledTimerWithTimeInterval来调整间隔(> 0.1)。

这是阻止主线程的坏方法。

使用下面的方法来“在某个时间后做某事”。

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

//  Do something taking a long time in background.

    [NSThread sleepForTimeInterval:0.2];

    //  Background thread has finished it's work.
    //  Call another block on main thread to do UI stuff like updating etc..
    dispatch_async(dispatch_get_main_queue(), ^{
        //  Here you are in the main thread again
        //  You can do whatever you want

    });
});