我有一个小png,我正在添加到一个视图,我很确定我以前工作但突然停止在iPad上工作,同时继续在iPad模拟器上正常工作。
以下是我用于将图像添加到视图中的代码...
UIImageView *bottomResizer = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"resizeLine.png"]];
bottomResizer.center = CGPointMake(bottomResizer.center.x, bottomResizer.center.y+self.frame.size.height-12);
bottomResizer.tag = 301;
[self addSubview:bottomResizer];
[bottomResizer release];
这发生在UIGestureRecognizerStateBegan事件中。以下代码删除了touchesEnded事件中的图像,即使您看不到也没有任何错误。
NSArray *subViews = [self subviews];
int count = [subViews count];
for (int i =count-1; i>=0; i--) {
if([[subViews objectAtIndex:i] tag] == 301) {
[[subViews objectAtIndex:i] removeFromSuperview];
}
}
我不认为这是我在代码中更改的任何内容,因为它在模拟器中有效。不确定下一步该问题的位置。我重置了模拟器,看看它是否会在重置后中断。我也清理了这个项目。
感谢。
约翰
答案 0 :(得分:1)
在此行UIImageView *bottomResizer = [[UIImageView alloc]...
然后在控制台“po [bottomResizer image]”
如果它是nil,那么资源没有被正确地复制到包中,或者你可能有一个设备无法加载的损坏图像。