我有一个包含UIImageViews的XIB。一个在左边,一个在右边,一个在中间。这三个UIImageViews中的每一个都在viewDidLoad方法中生成了图层:
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[UIApplication sharedApplication] setStatusBarHidden:YES];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[leftView setHidden:TRUE];
[rightView setHidden:TRUE];
[centerView setHidden:TRUE];
UIImageView *parentView = nil;
for(int i = 0; i < 3; i++) {
switch (i) {
case 0:
parentView = leftView;
break;
case 1:
parentView = rightView;
break;
default:
parentView = centerView;
break;
}
for(int layer = 0; layer < 5; layer++) {
UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240, 320)];
[view setOpaque:TRUE];
[parentView addSubview:view];
[view release];
}
UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240, 320)];
[view setImage:[UIImage imageNamed:@"frame"]];
[view setOpaque:TRUE];
[parentView addSubview:view];
[parentView bringSubviewToFront:view];
[view release];
}
parentView = nil;
[pool drain];
根据要显示的图像数量,应显示中间或左右图像。这在viewDidAppear方法中得到了解决:
[super viewDidAppear:animated];
[leftView setHidden:TRUE];
[rightView setHidden:TRUE];
[centerView setHidden:TRUE];
if(left != nil && right != nil) {
[leftView setHidden: FALSE];
[rightView setHidden:FALSE];
[centerView setHidden:TRUE];
[left fillView:leftView];
[right fillView:rightView];
} else if(left != nil) {
[leftView setHidden:TRUE];
[rightView setHidden:TRUE];
[centerView setHidden:FALSE];
[left fillView:centerView];
} else {
[leftView setHidden:TRUE];
[rightView setHidden:TRUE];
[centerView setHidden:TRUE];
}
左和右是类的本地属性。他们的fillView方法如下:
- (void)fillView:(UIImageView)imageView
{
for(Feature *feature in features) {
UIImageView *view = [[imageView subviews] objectAtIndex:feature.layer];
[view setTag:feature.value];
UIImage *image = [UIImage imageNamed:feature.fileName]];
[view setImage:image];
}
}
这是我展示XIB的方式:
ImageViewController imgViewCtrl = [[ImageViewController alloc] initWithNibName:@"ImageViewController" bundle:nil];
[parentView insertSubview:imgViewCtrl.view atIndex:0];
[parentView bringSubviewToFront:imgViewCtrl.view];
[imgViewCtrl.okayButton setHidden:TRUE];
[imgViewCtrl setLeft:result];
[imgViewCtrl setRight:target];
现在,问题。 我首先显示中间图像视图和其中的图像。一切都很好,俗气。 在此用户在另一个XIB中执行一些内部操作之后。当用户完成时,我想在所描述的XIB中显示两个图像。但大多数时候应用程序完全崩溃。整个iPod重新启动,我没有收到任何日志或错误消息。
我已经调试了1000次,一切正常,直到显示XIB。然后它被倾倒了。我检查了内存泄漏,修复了我发现的但仍然没有。我还检查了内存使用情况 - 应用程序使用最大2,5 MB。我认为不是那么多。