2

更新が必要になるたびに、GMGridViewすべてのセルが再作成されることに気付きました。これには長い時間がかかります。

再利用識別子を割り当てる方法、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;
    }
4

3 に答える 3

0

返事が遅れて申し訳ありません。

私は、シングル/グループテーブルビューの再利用可能なセルの場合、nilセルの宣言と割り当てにこのコードを追加するだけだと思います。

コード -:

//宣言中

 UItableViewCell *cell = [tbl_List dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"%d%d",indexPath.section,indexPath.row]];

// 割り当て中

if (セル == nil) {

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

 }
于 2013-05-23T11:14:32.597 に答える
0

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

GMGridCell を再利用するには、セルを割り当てた後に再利用識別子を割り当てる必要があります

    cell.reuseIdentifier =  [NSString stringWithFormat:@"Cell%i", index];
于 2013-05-06T04:37:03.540 に答える
0

再利用されている場合、コードはセルに対して何もしないようです。この投稿は、正しい方向を示しているはずです... GitHub

于 2012-05-01T21:42:41.393 に答える