2012-03-24 5 views
2

Ich habe festgestellt, dass jedes Mal, wenn mein GMGridView aktualisiert werden muss, es alle Zellen neu erstellt, was sehr lange dauert.iOS GMGridView wie GMGridViewCell Zellen wiederverwenden?

Gibt es eine Möglichkeit, einen Wiederverwendungsidentifikator GMGridViewCell zuzuweisen oder irgendwie sicherzustellen, dass sie wiederverwendbar sind?

Hier ist der Code, den ich jedes Mal alle sichtbaren Ansichten neu erstellt.

- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index 
    { 
     NSLog(@"Creating view indx %d", index); 

     CGSize size = [self sizeForItemsInGMGridView:gridView]; 

     GMGridViewCell *cell = [gridView dequeueReusableCell]; 

     if (!cell) 
     { 
      cell = [[GMGridViewCell alloc] init]; 
      cell.deleteButtonIcon = [UIImage imageNamed:@"close_x.png"]; 
      cell.deleteButtonOffset = CGPointMake(30, -20); 

      UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 57, 57)]; 

      cell.userData = [[IconFile allObjects] objectAtIndex:index]; 

      UIImageView* imageView = [[UIImageView alloc] initWithFrame:view.frame]; 
      NSIndexPath* indexPath = [NSIndexPath indexPathForRow:index inSection:0]; 
      IconFile* iconFile_ = [self.fetchedResultsController objectAtIndexPath:indexPath]; 

    //  imageView.image = [UIImage imageNamed:@"retina_114x114_1.png"]; 
      imageView.image = [UIImage imageWithData:iconFile_.image114]; 
      [view addSubview:imageView]; 
      imageView.center = view.center; 
      imageView.layer.masksToBounds = YES; 
      imageView.layer.cornerRadius = 9; 

      view.backgroundColor = [UIColor clearColor]; 
    //  view.layer.masksToBounds = YES; 
    //  view.layer.cornerRadius = 9; 
      view.layer.shadowColor = [UIColor grayColor].CGColor; 
      view.layer.shadowOffset = CGSizeMake(5, 5); 
      view.layer.shadowPath = [UIBezierPath bezierPathWithRect:view.bounds].CGPath; 
      view.layer.shadowRadius = 9; 

      ShadowLabel *label = [[ShadowLabel alloc] initWithFrame:CGRectMake(0,0,72,21)]; 
      label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    //  label.text = (NSString *)[_data objectAtIndex:index]; 
      label.text = iconFile.springBoardName; 

      label.layer.shadowPath = [UIBezierPath bezierPathWithRect:label.bounds].CGPath; 
      label.layer.shadowRadius = 9;   
      label.textAlignment = UITextAlignmentCenter; 
      label.backgroundColor = [UIColor clearColor]; 
      label.textColor = [UIColor whiteColor]; 
      label.font = [UIFont boldSystemFontOfSize:11]; 
      [view addSubview:label]; 
      label.center = CGPointMake(size.width/2, 60); 


      cell.contentView = view; 
     }else{ 

    //  [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; 
    //   
    //  UILabel *label = [[UILabel alloc] initWithFrame:cell.contentView.bounds]; 
    //  label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    //  label.text = (NSString *)[_data objectAtIndex:index]; 
    //  label.textAlignment = UITextAlignmentCenter; 
    //  label.backgroundColor = [UIColor clearColor]; 
    //  label.textColor = [UIColor blackColor]; 
    //  label.font = [UIFont boldSystemFontOfSize:20]; 
    //  [cell.contentView addSubview:label]; 
     } 
     return cell; 
    } 
+0

i die gleiche Beispielcode verwendet haben In meiner App und ich habe 76 Ansichten und es erstellt nur 31 Ansichten erstellt es nicht jedes Mal eine neue Ansicht. – Leena

Antwort

0

Ihr Code scheint der Zelle nichts zu tun, wenn sie erneut verwendet wird. Dieser Beitrag sollte Sie in die richtige Richtung zeigen ... GitHub

0

Vielleicht ist das zu spät, um diese Frage zu beantworten, aber ich habe eine Antwort dafür.

Für Reusing GMGridCell, müssen Sie Wiederverwendung Kennung zuweisen, nachdem Sie Ihr Handy Alloc wie diese für späte Antwort

cell.reuseIdentifier = [NSString stringWithFormat:@"Cell%i", index]; 
0

Leider werden.

Ich denke für wiederverwendbare Zelle auf Sigle/Gruppe Tabellenansicht fügen Sie einfach diesen Code auf Deklaration und Zuweisung auf Nullzelle.

-Code -:

// Deklarieren

//

Zuweisung if (Zelle == null) {

 cell = [[UItableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"%d%d",indexPath.section,indexPath.row]]; 

} 
Verwandte Themen