Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS GMGridView如何重用GMGridViewCell单元格?_Iphone_Objective C_Ios_Gmgridview_Gmgridviewcell - Fatal编程技术网

Iphone iOS GMGridView如何重用GMGridViewCell单元格?

Iphone iOS GMGridView如何重用GMGridViewCell单元格?,iphone,objective-c,ios,gmgridview,gmgridviewcell,Iphone,Objective C,Ios,Gmgridview,Gmgridviewcell,我注意到每当我的GMGridView需要刷新时,它都会重新创建所有单元格,这需要很长时间 是否有办法将重用标识符分配给GMGridViewCell,或者以某种方式确保它们是可重用的 下面是我的代码,每次都会重新创建所有可见视图 - (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index { NSLog(@"Creating view indx %d"

我注意到每当我的
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;
    }

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

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

也许现在回答这个问题已经太迟了,但我有一个答案

为了重用GMGridCell,您需要在分配单元后分配重用标识符 可能是这样

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

也许现在回答这个问题已经太迟了,但我有一个答案

为了重用GMGridCell,您需要在分配单元后分配重用标识符 可能是这样

    cell.reuseIdentifier =  [NSString stringWithFormat:@"Cell%i", index];
对不起,迟了答复

我认为对于sigle/group tableview上的可重用单元,只需在nil单元上声明和分配时添加此代码

代码-:

//宣布

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

如果(单元格==nil) {

对不起,迟了答复

我认为对于sigle/group tableview上的可重用单元,只需在nil单元上声明和分配时添加此代码

代码-:

//宣布

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

如果(单元格==nil) {


我在我的应用程序中使用了相同的示例代码,我有76个视图,它只创建了31个视图。我没有每次创建新视图。我在我的应用程序中使用了相同的示例代码,我有76个视图,它只创建了31个视图。它没有每次创建新视图。