gpt4 book ai didi

iphone - iOS GM GridView 如何重用GM GridView Cell 单元格?

转载 作者:行者123 更新时间:2023-12-01 16:57:56 27 4
gpt4 key购买 nike

我注意到每次我的GMGridView需要刷新,它重新创建所有单元格,这需要很长时间。

有没有办法将重用标识符分配给 GMGridViewCell或者以某种方式确保它们是可重复使用的?

这是我每次重新创建所有可见 View 的代码。

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

最佳答案

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

关于iphone - iOS GM GridView 如何重用GM GridView Cell 单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9850021/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com