- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的一个 View Controller 的 loadView: 方法中的一些代码出现问题。本质上,我有一个 View ,它以更大的 View (在 iPad 上)为中心,并具有一些以编程方式加载到其中的标签、按钮和图标。
当 View Controller 调用 dealloc 方法并尝试释放时,会出现此问题。我收到 -[CALayer release]: message sent to deallocated instance 错误,并且应用程序崩溃。
从阅读有关此错误的内容来看,我似乎过度释放了某些内容,但我认为情况并非如此:下面的代码是麻烦制造者,我已经尝试过对所有内容进行自动释放和手动释放调用,以及干脆不释放它们(我知道,我知道,这很糟糕),但它继续造成破坏。
container = [[UIView alloc] initWithFrame:CGRectNull];
container.autoresizingMask = ( UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin );
container.frame = CGRectMake( (viewSize.width-320)/2, (viewSize.height-480)/2, 320, 480);
[self.view addSubview:container];
UILabel *welcomeTo = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
welcomeTo.backgroundColor = [UIColor clearColor];
welcomeTo.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:18.0];
welcomeTo.frame = CGRectMake(23, 15, 103, 24);
welcomeTo.shadowColor = [UIColor blackColor];
welcomeTo.shadowOffset = CGSizeMake( 0, 1 );
welcomeTo.text = @"Welcome to";
welcomeTo.textAlignment = UITextAlignmentLeft;
welcomeTo.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:welcomeTo];
UILabel *progressions = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
progressions.backgroundColor = [UIColor clearColor];
progressions.font = [UIFont fontWithName:@"HelveticaNeue-BoldItalic" size:44.0];
progressions.frame = CGRectMake(20, 30, 280, 56);
progressions.shadowColor = [UIColor blackColor];
progressions.shadowOffset = CGSizeMake( 0, 1 );
progressions.text = @"Progressions";
progressions.textAlignment = UITextAlignmentCenter;
progressions.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:progressions];
UILabel *blurb = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
blurb.backgroundColor = [UIColor clearColor];
blurb.font = [UIFont fontWithName:@"HelveticaNeue" size:14.0];
blurb.frame = CGRectMake(23, 100, 274, 51);
blurb.numberOfLines = 3;
blurb.shadowColor = [UIColor blackColor];
blurb.shadowOffset = CGSizeMake( 0, 1 );
blurb.text = @"Kick off the fun by adding some content, or if you're not sure what you're doing, check out the \"Getting Started\" guide!";
blurb.textAlignment = UITextAlignmentLeft;
blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:blurb];
UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(20, 170, 280, 88)];
[button1 setBackgroundImage:[UIImage imageNamed:@"emptyButtonLarge.png"] forState:UIControlStateNormal];
[button1 setBackgroundImage:[UIImage imageNamed:@"emptyButtonLargeHighlighted.png"] forState:UIControlStateHighlighted];
[button1 addTarget:self action:@selector(createChart:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button1];
[button1 release];
UIImageView *icon1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"addchart.png"]];
icon1.frame = CGRectMake(30, 180, icon1.frame.size.width, icon1.frame.size.height);
[container addSubview:icon1];
[icon1 release];
UILabel *button1title = [[[UILabel alloc] initWithFrame:CGRectMake(110, 185, 180, 20)] autorelease];
button1title.backgroundColor = [UIColor clearColor];
button1title.font = [UIFont boldSystemFontOfSize:17.0];
button1title.shadowColor = [UIColor blackColor];
button1title.shadowOffset = CGSizeMake( 0, 1 );
button1title.text = @"Create a Chart";
button1title.textAlignment = UITextAlignmentLeft;
button1title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button1title];
UILabel *button1blurb = [[[UILabel alloc] initWithFrame:CGRectMake(110, 205, 180, 40)] autorelease];
button1blurb.backgroundColor = [UIColor clearColor];
button1blurb.font = [UIFont systemFontOfSize:13.0];
button1blurb.numberOfLines = 2;
button1blurb.shadowColor = [UIColor blackColor];
button1blurb.shadowOffset = CGSizeMake( 0, 1 );
button1blurb.text = @"A cheat sheet for a displaying a song in any key.";
button1blurb.textAlignment = UITextAlignmentLeft;
button1blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button1blurb];
UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(20, 270, 280, 88)];
[button2 setBackgroundImage:[UIImage imageNamed:@"emptyButtonLarge.png"] forState:UIControlStateNormal];
[button2 setBackgroundImage:[UIImage imageNamed:@"emptyButtonLargeHighlighted.png"] forState:UIControlStateHighlighted];
[button2 addTarget:self action:@selector(createSet:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button2];
[button2 release];
UIImageView *icon2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"addset.png"]];
icon2.frame = CGRectMake(30, 280, icon2.frame.size.width, icon2.frame.size.height);
[container addSubview:icon2];
[icon2 release];
UILabel *button2title = [[[UILabel alloc] initWithFrame:CGRectMake(110, 285, 180, 20)] autorelease];
button2title.backgroundColor = [UIColor clearColor];
button2title.font = [UIFont boldSystemFontOfSize:17.0];
button2title.shadowColor = [UIColor blackColor];
button2title.shadowOffset = CGSizeMake( 0, 1 );
button2title.text = @"Create a Set";
button2title.textAlignment = UITextAlignmentLeft;
button2title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button2title];
UILabel *button2blurb = [[[UILabel alloc] initWithFrame:CGRectMake(110, 305, 180, 40)] autorelease];
button2blurb.backgroundColor = [UIColor clearColor];
button2blurb.font = [UIFont systemFontOfSize:13.0];
button2blurb.numberOfLines = 2;
button2blurb.shadowColor = [UIColor blackColor];
button2blurb.shadowOffset = CGSizeMake( 0, 1 );
button2blurb.text = @"A collection of charts that can be displayed like a book.";
button2blurb.textAlignment = UITextAlignmentLeft;
button2blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button2blurb];
UIButton *button3 = [[UIButton alloc] initWithFrame:CGRectMake(20, 370, 280, 40)];
[button3 setBackgroundImage:[UIImage imageNamed:@"emptyButtonSmall.png"] forState:UIControlStateNormal];
[button3 setBackgroundImage:[UIImage imageNamed:@"emptyButtonSmallHighlighted.png"] forState:UIControlStateHighlighted];
[button3 addTarget:self action:@selector(gettingStarted:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button3];
[button3 release];
UILabel *button3title = [[[UILabel alloc] initWithFrame:CGRectMake(20, 370, 280, 36)] autorelease];
button3title.backgroundColor = [UIColor clearColor];
button3title.font = [UIFont boldSystemFontOfSize:17.0];
button3title.shadowColor = [UIColor blackColor];
button3title.shadowOffset = CGSizeMake( 0, 1 );
button3title.text = @"Getting Started";
button3title.textAlignment = UITextAlignmentCenter;
button3title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button3title];
UILabel *version = [[[UILabel alloc] initWithFrame:CGRectMake(20, 420, 280, 20)] autorelease];
version.backgroundColor = [UIColor clearColor];
version.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:12.0];
version.shadowColor = [UIColor blackColor];
version.shadowOffset = CGSizeMake( 0, 1 );
version.text = [NSString stringWithFormat:@"Version v%@ (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"], kRevisionNumber];
version.textAlignment = UITextAlignmentCenter;
version.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:version];
容器属性在dealloc方法中释放,如下:
- (void)dealloc {
[leather release];
[backButton release];
[container release];
[super dealloc];
}
人们可以提供的任何答案或建议将不胜感激!我真的被难住了。
最佳答案
使用“Zombies”Instrument 在模拟器中分析您的应用程序。
运行你的应用一段时间,然后做任何你必须做的事情来让你的应用崩溃。当它出现时,您将看到如下图所示的弹出窗口,并且它将停止应用程序的分析:
然后,如果您单击地址 (0x158b3c00) 旁边的小箭头...它将带您进入过度释放的对象(僵尸)的对象保留/释放历史记录。
如果您突出显示上面保留计数变为 -1 的行,然后打开“查看”->“扩展详细信息”,它应该会指向堆栈跟踪以及代码中对象被过度释放的行:
如果您双击发生该问题的类,它将打开您的源代码并显示错误的代码行:
关于iphone - -[CALayer释放] : message sent to deallocated instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7402171/
如果我将 cornerRadius 属性设置为我想要 mask 的图层,我只能设法做到这一点。 我正在努力实现: 整个蓝色的 UIView。 全背景为红色的 CALayer。 maskLayer,比第
我正在尝试用另一层 (stickerMask) 的图像遮盖一个 CALayer(newSticker),如下所示: func placeSticker(location: CGPoint) {
我有一个 UIBezierPaths 数组,我正在循环创建一个 CALayer。生成 CALayer 的代码如下所示: let layer = CAShapeLayer() layer.path =
我正在尝试使用 CALayers 制作一个 donut 形状。一个 CALayer 将是一个大圆圈,另一个将是一个位于其中心的小圆圈,将其遮盖。 大圆圈显示正常,但每当我调用 circle.mask
我有以下代码: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CALayer
我有一系列随机放置在屏幕上的图层。添加每一层时,它都位于所有其他层之上。 最终,一个层被其他层完全覆盖。此时,我想从内存中删除图层。 有什么方法可以知道一个层何时被其他层覆盖(100% 或部分)? 每
我正在尝试子类化 CALayer 以用作另一层上的 mask 。 我想使用我的 CALayer 子类代替 CAGradientLayer 并将其用于渐变蒙版,如 here 所述. 不过,我希望使用自定
在 XCode 中创建一个简单的项目 设置 View 以接收多点触控事件 在touchesBegan中响应,检测到触摸事件时创建CALayer 为 CALayer 制作不透明度淡出动画 当动画停止时,
我找不到这个问题的答案。 我想知道如何使 calayer 中的图像大小小于 calayer 的边界大小。 我在 iPad 游戏中有几个 pawn,每个都是一个 CALayer,我让它们通过 conte
我正在使用 Cocoa 为 Mac 编写游戏。我目前正在实现 HitTest ,并发现 CALayer 提供 HitTest ,但似乎没有实现 alpha 属性。由于我有时会将许多 CALayer 堆
我们正在尝试创建一个自定义的 CIFilter 以添加到我们的 CALayer 的顶部。 如何只有默认的 CIFilter 似乎可以在 CALayer 上工作。 我们在添加的 ViewControll
我们正在尝试创建一个自定义的 CIFilter 以添加到我们的 CALayer 的顶部。 如何只有默认的 CIFilter 似乎可以在 CALayer 上工作。 我们在添加的 ViewControll
我有很多 UIImage 实例。我将在 TableView 情况下的 View 之间移动它们。我有两个选择: 每个 UIImage 有一个 CALayer,将 CALayer 移动到不同的 View
我想按时间顺序依次添加多个 CALayer。我可以使用此链接向视频文件添加一层 Here .现在我的问题是如何将多个 CALayer 添加到视频文件。 提前致谢.. 最佳答案 最直接的方法是将多个层捆
我正在尝试实现一个具有隐式动画属性的图层,但我看到了一些非常奇怪的行为。这是一个简单的层,它演示了我的意思: class CustomLayer: CALayer { override ini
我正在尝试构建一个动画圆,该圆将顺时针绘制,直到它变成完整的圆,如 iPhone Core Animation - Drawing a Circle 所示。 问题是CALayer对象未添加或构建。我测
我有一个 CALayer在 AVMutableComposition淡入,应该在屏幕上停留一段时间然后消失。问题是,它应该在没有动画的情况下消失,但是 CABasicAnimation最短持续时间为
是否可以在 iPhone 上对 CALayer 的边界进行动画处理?如何实现?谢谢! 最佳答案 是的,这是可能的。 [UIView beginAnimations:nil context:NULL];
调查后Custom UITableViewCell backgroundView & selectedBackgroundView ,我注意到每层 backgroundView 和 selectedB
我目前正在尝试使用基于 CALayers 的核心动画制作 2D 游戏。我已经弄清楚了用户 Sprite 层,但现在它归结为游戏对象。 物体(用户必须避开)将从屏幕顶部掉落,如果它们从未与用户接触就会消
我是一名优秀的程序员,十分优秀!