2012-03-24 6 views
2

GMGridViewをリフレッシュする必要があるたびに、すべてのセルが再作成されるため、時間がかかります。iOS GMGridView GMGridViewCellセルを再利用する方法は?

再利用識別子をGMGridViewCellに割り当てる方法はありますか、何とか再利用可能であることを確認してください。

ここでは、すべての表示可能なビューを毎回再作成するコードを示します。

- (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

場合

を割り当てる

//宣言

//私のアプリでは、私は76ビューがあり、それは毎回新しいビューを作成していないだけ31ビューを作成しています。 – Leena

答えて

0

コードが再利用されてもセルに何もしないようです。この投稿は正しい方向にあなたを指し示す必要があります... GitHub

0

この質問に答えるには遅すぎるかもしれませんが、私はこれに対する答えがあります。再利用のためにGMGridCell

、あなたはあなたのセル が、返事が遅れて申し訳ありません、この

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

等であってもよいのalloc後に再利用識別子を割り当てる必要があります。

sigle/group tableviewの再利用可能なセルは、宣言とnilセルの割り当てにこのコードを追加するだけです。

コード - :私は同じサンプルコードを使用している(セル== NIL) {

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

} 
関連する問題