iOS GMGridView, как повторно использовать ячейки GMGridViewCell? - PullRequest
2 голосов
/ 24 марта 2012

Я заметил, что каждый раз, когда мой 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;
    }

Ответы [ 3 ]

0 голосов
/ 06 мая 2013

Может быть, это слишком поздно, чтобы ответить на этот вопрос, но у меня есть ответ на этот вопрос.

Для повторного использования GMGridCell вам необходимо назначить идентификатор повторного использования после выделения ячейки Может быть так

    cell.reuseIdentifier =  [NSString stringWithFormat:@"Cell%i", index];
0 голосов
/ 23 мая 2013

Извините за поздний ответ.

Я думаю, что для многоразовой ячейки в табличном представлении sigle / group просто добавьте этот код при объявлении и распределении в нулевой ячейке.

Код -:

// Декларирование

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

// выделение

if (cell == nil) {

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

 }
0 голосов
/ 02 мая 2012

Ваш код, похоже, ничего не делает с ячейкой, если она используется повторно.Этот пост должен указать вам правильное направление ... GitHub

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...