- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
据推测,该应用程序在显示 UICollectionView 时崩溃了。它还会创建低内存崩溃日志。如何减少 UICollectionView 中的内存使用量?我在项目中使用 ARC。请帮助...(附言,下面是我的代码)
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [untaggedImagesArray count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
@autoreleasepool {
static NSString *identifier = @"imageCell";
imageCell *cvc = (imageCell *)[self.iamgesCollectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
if(cvc == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"imageCell" owner:nil options:nil];
for(id currentObject in topLevelObjects){
if([currentObject isKindOfClass: [imageCell class]]){
cvc = (imageCell*)currentObject;
break;
}
}
}
NSString *path = [untaggedImagesArray objectAtIndex:indexPath.row];
NSString *path = [untaggedImagesArray objectAtIndex:indexPath.row];
//[self performSelectorInBackground:@selector(getImage:) withObject:path];
UIImage *cache_image = [images_cache objectForKey:path];
if(cache_image)
{
[cvc.imageView setImage:cache_image];
}
else
{
[self performSelectorInBackground:@selector(getImage:) withObject:path];
//UIImage *img = [UIImage imageWithContentsOfFile:path];
[images_cache setObject:cellImage forKey:path];
[cvc.imageView setImage:cellImage];
}
if([preTaggedPaths containsObject:path]){
[cvc.tagLabel setText:[tagStringsDict valueForKey:[NSString stringWithFormat:@"%d",indexPath.row]]];
[cvc setUserInteractionEnabled:NO];
}else{
[cvc.tagLabel setText:@""];
[cvc setUserInteractionEnabled:YES];
}
if([selectedImagesPath containsObject:path]){
[cvc.checkImageView setImage:[UIImage imageNamed:@"checkbox_small_selected.png"]];
}else{
[cvc.checkImageView setImage:[UIImage imageNamed:@"checkbox_small_unselected.png"]];
}
//
return cvc;
}
}
-(void)getImage:(NSString*)path{
cellImage = [UIImage imageWithContentsOfFile:path];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"clicked to select at index%d",indexPath.row);
imageCell *cvc = (imageCell*)[self.iamgesCollectionView cellForItemAtIndexPath:indexPath];
NSString *pathString = [untaggedImagesArray objectAtIndex:indexPath.row];
[cvc.checkImageView setImage:[UIImage imageNamed:@"checkbox_small_selected.png"]];
[selectedImagesPath addObject:pathString];
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"clicked to DEselect at index%d",indexPath.row);
imageCell *cvc = (imageCell*)[self.iamgesCollectionView cellForItemAtIndexPath:indexPath];
NSString *pathString = [untaggedImagesArray objectAtIndex:indexPath.row];
[cvc.checkImageView setImage:[UIImage imageNamed:@"checkbox_small_unselected.png"]];
[selectedImagesPath removeObject:pathString];
// [cvc setSelected:NO];
}
-
(void)getImage:(NSString*)path{
//cellImage = [UIImage imageWithContentsOfFile:path];
NSLog(@"image path: %@", path);
cellImage = [UIImage imageNamed:path];
}
最佳答案
你是说崩溃是内存不足引起的!
一个可能的问题是你的图片加载机制(你的图片有多大?):
[UIImage imageWithContentsOfFile:path];
每次都会为您的 Collection View 中的每个单元格执行此操作。
[UIImage imageNamed:@"name"];
例如正在缓存图像,而 imageWithContentsOfFile 则没有!
所以 UIImage 的方法 imageNamed:
和 imageWithContentsOfFile
做的事情略有不同。 imageNamed
在特殊的系统缓存中加载图像,然后使用该图像路径的 future 调用将返回缓存中的图像,而不是从磁盘重新加载它。 imageWithContentsOfFile
只是在您指定的路径加载图像,但不进行缓存。为同一图像多次调用 imageWithContentsOfFile
将导致内存中有多个副本。
如果这是您的问题,请尝试缓存图像或使用智能方式仅加载当前正在显示的图像。
关于iphone - UICollectionView 在 iPhone 3GS 上的 iOS 6.0 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14278068/
IE 似乎在来自未压缩的 raphaeljs 1.4.7 的以下第 2207 行(当然,在我的代码的上下文中): gs.left != (t = left + "px") && (gs.left =
由于太复杂的原因无法在这里解释,我需要在 x86 的子集平台上运行 x86 GCC 编译的 Linux 程序。该平台没有 %gs 寄存器,这意味着它必须被模拟,因为 GCC 依赖于 %gs 寄存器的存
我读了 this 线程,它帮助我正确地解决了取消引用的问题,但后来我去创建了帖子答案作者所说要避免的情况,哈哈。 我想要完成的是创建一个基本的文件浏览器(根据我正在阅读的book)。下面的代码应该读取
我读过另一个discussion . 我知道%gs是段寄存器,存放段描述符。操作系统获取段描述符并计算物理地址。大多数时候,段描述符对程序员来说是不透明的。我可以做一些技巧,比如拦截系统调用 set_
最近,我一直在尝试用 C++ 编写一个与 MySQL 服务器通信的小测试程序。我目前正在使用 MySQL Connector/C++ 作为我的 API 来连接到我的数据库服务器。我花了很长时间才让它运
我是新来的。我正在使用应用程序脚本插件,我想知道如何使用侧边栏中复选框的选中值来启动特定的 GS 功能? 以下是侧边栏的 HTML 示例: Please select the c
所以我知道以下寄存器及其用途应该是什么: CS = 代码段(用于 IP) DS = 数据段(用于 MOV) ES = 目标段(用于 MOVS 等) SS = 堆栈段(用于 SP) 但是以下寄存器的用途
我正在根据OSDev Wiki中的信息编写一个操作系统。以及一些相关书籍。我发现跳入保护模式后,段初始化例程没有正确执行。这是我的第二阶段加载器和内核代码: ; stage2 ; still -f b
对此很陌生 单元格数据如下: colx aa, bbb oue, hed, ono hud 需要它变成: colx coly colz aa, bbb
/* 960 Grid System ~ Core CSS. Learn more ~ http://960.gs/ Licensed under GPL and MIT. */ /*
使用这段代码,布局可以工作,但向右有一个小的偏移量(3px 或类似的东西)。 (搜索阴影是仅与宽度和背景图像相关的自定义类,没有填充/边距等) 看起来像这
我对使用这个系统很感兴趣,但我想知道是否有人找到了任何好的替代品。特别是我正在寻找一些布局系统,它可以让我构建一个在浏览器、iPad 和手机上都能正常工作的 HTML5 布局。 有人对我应该考虑的其他
我在使用 GhostScript 将 ps 文件转换为 JPG 时遇到问题。 我已经成功地让它在我的 Win7 机器上运行,但由于某种原因它在我的 Linux VM 上不起作用。我真的不确定如何在那里
我使用下面的代码根据浏览器窗口的大小选择不同的 css 文件。但是,当我将窗口调整为该大小时,第一个似乎不起作用,即使我刷新页面也是如此。我不确定我应该做什么来解决这个问题。谢谢。 @import u
我正在尝试学习 960 网格系统。我的左侧正文显示在右侧,反之亦然。我的意图是将这两个框放在同一条线上。左侧正文在页面上的显示位置也高于右侧正文。 有什么想法吗?使困惑!
我在我创建的站点中使用 978.gs 系统,但它在页面顶部插入一个小带,将内容稍微向下移动。我不希望发生这种情况。 有问题的站点是 Located Here查看页面顶部。 我的 CSS 代码是
我正在使用以下查询创建一个以组分隔符 (GS) 作为分隔符的外部表 CREATE EXTERNAL TABLE IF NOT EXISTS icephase2Demo.GS_TEST1 ( Rando
我对 x86 汇编中冒号的使用有点困惑。我知道在实模式下 %gs:0x14 将是 %gs 的地址左移 4 位并加上 0x14。但是在保护模式下是一样的吗?例如在保护模式下, movl %gs:0x14
void return_input (void){ char array[30]; gets (array); printf("%s\n", array); } 在gcc中编译后,该
我在一行中有 4 列,根据我在每一列中输入的信息量,它们会有不同的高度。如果给它们加上背景色,您会看到这一点。 我如何给其他列高度最大的列的高度? 最佳答案 您可以使用 jQuery 来执行此操作。
我是一名优秀的程序员,十分优秀!