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

回答这个问题可能为时已晚,但我有一个答案。

对于重用GMGridCell,您需要在分配单元格后分配重用标识符可能是这样的

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

抱歉回复晚了。

我认为对于单/组表视图上的可重用单元,只需在 nil 单元上声明和分配此代码即可。

代码 -:

//声明

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

// 分配

如果(细胞 == 零){

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

 }
于 2013-05-23T11:14:32.597 回答
0

如果重复使用,您的代码似乎对单元格没有任何作用。这篇文章应该为你指明正确的方向...... GitHub

于 2012-05-01T21:42:41.393 回答