gpt4 book ai didi

iphone - 在 ScrollView 崩溃时需要帮助

转载 作者:行者123 更新时间:2023-12-03 16:23:43 25 4
gpt4 key购买 nike

我正在尝试在iPhone的Xcode中显示约53张图像,但第37张图像会使我的整个应用崩溃!如果有人在我的代码中发现任何错误,非常感谢您的帮助。谢谢!!

我想我不会在某个地方发布图片...只是不确定该怎么做!

#import "MyProjectViewController.h"

@implementation MyProjectViewController


@synthesize scrollView1;

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


const CGFloat kScrollObjHeight = 320.0;
const CGFloat kScrollObjWidth = 480.0;
const NSUInteger kNumImages = 53;


- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;

curXLoc += (kScrollObjWidth);
}
}

[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}

- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];

[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = YES;
scrollView1.scrollEnabled = YES;
scrollView1.pagingEnabled = YES;




NSUInteger i;

for (i = 1; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"c1_%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i;
[scrollView1 addSubview:imageView];
[imageView release];

}

[self layoutScrollImages];

}



- (void)dealloc
{
[scrollView1 release];

[super dealloc];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}


@end

谢谢!!!!!

最佳答案

图片有多大?我怀疑问题不在于代码本身,而在于iPhone / iPod的内存限制-如果加载大图像,它们只会消耗所有内存,并且程序已关闭。

关于iphone - 在 ScrollView 崩溃时需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1004748/

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