Los contenidos son aleatorios en GridView

Soy nuevo en el desarrollo de IOS. Estoy usando GridView personalizado para cargar el contenido en mi proyecto, y funciona bien para Simulator cuando el contenido se vuelve a cargar. Pero en iPad, el contenido se baraja cuando se vuelve a cargar.

- (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 networkingColor]; 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]; } 

Estás comparando la RAM del iPad y la RAM de tu máquina. No es justo.

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

Intente ajustar el intervalo (> 0.1) estableciendo, scheduledTimerWithTimeInterval .

Y es una mala manera de bloquear el hilo principal.

Usa el enfoque de bloques a continuación para "hacer algo después de algún time".

 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 }); });