Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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
Ios UICollectionView中的性能_Ios_Objective C_Performance_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Ios UICollectionView中的性能

Ios UICollectionView中的性能,ios,objective-c,performance,uicollectionview,uicollectionviewcell,Ios,Objective C,Performance,Uicollectionview,Uicollectionviewcell,我使用的是带有自定义单元格的UICollectionView的标准方法。我已经注册了单元格和所有这些,但是当collectionview开始用项目填充整个屏幕时,性能会下降很多,变得滞后。只有几个项目时没有问题。集合视图是动态的,因此用户可以根据需要添加项目。同时移除。有什么问题吗?或者解决办法来扭转局面 谢谢你的帮助 编辑: viewDidLoad: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup af

我使用的是带有自定义单元格的UICollectionView的标准方法。我已经注册了单元格和所有这些,但是当collectionview开始用项目填充整个屏幕时,性能会下降很多,变得滞后。只有几个项目时没有问题。集合视图是动态的,因此用户可以根据需要添加项目。同时移除。有什么问题吗?或者解决办法来扭转局面

谢谢你的帮助

编辑:

viewDidLoad:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[_projectsCollectionView registerNib:[UINib nibWithNibName:@"Cell" bundle:nil] forCellWithReuseIdentifier:@"Cell"];

// Configure the style of the three big buttons
prepareButton.layer.cornerRadius = 7;
prepareButton.layer.borderWidth = 1;
prepareButton.layer.borderColor = [UIColor blueColor].CGColor;

aboutButton.layer.cornerRadius = 7;
aboutButton.layer.borderWidth = 1;
aboutButton.layer.borderColor = [UIColor blueColor].CGColor;

createButton.layer.cornerRadius = 7;
createButton.layer.borderWidth = 1;
createButton.layer.borderColor = [UIColor blueColor].CGColor;

editButton.layer.cornerRadius = 7;
editButton.layer.borderWidth = 1;
editButton.layer.borderColor = [UIColor blueColor].CGColor;
// (note - may prefer to use the tintcolor of the control)


// Set up projectsCollectionView
_projectsCollectionView.delegate = self;
_projectsCollectionView.dataSource = self;

}
视图将显示:

-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_objects = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"myProjects"]];
[_projectsCollectionView reloadData];
}
我的cellForItemAtIndexPath:

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ProjectCell *cell = (ProjectCell *)[cv dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
// Get the amount of subjects
        NSMutableArray *subjects = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:_objects[indexPath.row
]]];

// Count the subjects
int subjectsCount = [subjects count];

// Set the text and integer value
cell.projectLabel.text = _objects[indexPath.row];
cell.projectCount.text = [NSString stringWithFormat:@"%i",subjectsCount];

cell.layer.cornerRadius = 16;
cell.layer.borderWidth = 1;
cell.layer.borderColor = [UIColor lightGrayColor].CGColor;
// (note - may prefer to use the tintcolor of the control)

return cell;
}
用户添加新项目代码:

                // Ready to add the project, go ahead
                [_objects insertObject:newProject atIndex:0];
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
                [_projectsCollectionView insertItemsAtIndexPaths:@[indexPath]];

                [[NSUserDefaults standardUserDefaults] setObject:_objects forKey:@"myProjects"];
尝试添加

cell.layer.shouldRasterize = YES;
这会有帮助。所有这些工作人员:

cell.layer.cornerRadius = 16;
cell.layer.borderWidth = 1;
cell.layer.borderColor = [UIColor lightGrayColor].CGColor;

您应该在自定义单元格类中执行此操作

阅读我的上一篇文章。可能会有帮助。

分享您的代码(特别是创建UICollectionViewCell的代码)您试图加载到您的单元格中的内容是一个重要因素,请让我们知道您的代码抱歉,忘记:)立即上载您的想法@Shai-慢慢来:)NSMutableArray*主题=[NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults]objectForKey:[u objects[indexPath.row]];这太慢了,太棒了!所以要顺利得多!谢谢!:)有一个问题,我应该在自定义类中的什么位置添加您提到的其他代码?initWithFrame没有做到这一点,我无法创建viewDidLoad方法@mvadimt这里有方法-(void)awakeFromNib,只需在那里添加:self.layer.cornerRadius=16;self.layer.borderWidth=1;self.layer.borderColor=[UIColor lightGrayColor].CGColor;另外,不要忘记在custom中导入“QuartzCore/CALayer.h”cell@Robert我添加了一个解释:“UIView子类有一个代码,它为你提供了一个不透明的圆形边界和中间透明的孔的视图。你应该像平常一样创建所需的视图,然后你可以在视图中添加有孔的视图。可视化就是。”