我正在我的 ipad 上尝试我的代码,但它崩溃了。设备日志上没有任何内容,只有未知类型和未知进程。所以我确实挖了。我tot这是一个内存问题。我发现我不能在水平滚动视图上添加这么多图像。我有100多个。
这是我的代码
for(int index=0; index < 166; index++)
{
UIImageView *imgscv = [[UIImageView alloc] init];
imgscv.bounds = CGRectMake(0, 0, 200, 250);
imgscv.frame = CGRectMake(5+xOffset, 5, 200, 250);
imgscv.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",index-1]];
[images insertObject:imgscv atIndex:index];
scrollview.contentSize = CGSizeMake(scrollWidth+xOffset,110);
[scrollview addSubview:[images objectAtIndex:index]];
xOffset += 205;
}
当我将 for 循环中索引的上限更改为 16 时,一切都很好。是这样吗?有限制吗?您可能会建议任何修复或替代方案?