由Interface Builder创建的UIButton正在崩溃 [英] UIButton, created by Interface Builder, is crashing

查看:90
本文介绍了由Interface Builder创建的UIButton正在崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经缩小了一个丑陋的bug,但由于它似乎是nib / Interface Builder内部的东西,我不知道下一步该做什么。

I have narrowed down an ugly bug, but since it seems like something internal to the nib/Interface Builder, I'm at a loss of what to do next.

我在IB中创建了一个UIView,它起到了自定义对话框的作用。它显示一条消息和两个按钮。 (继续或取消。)两个按钮都在Interface Builder中设置了背景图像。

I've got a UIView created in IB which functions as a custom dialog box. It shows a message and two buttons. (Proceed or Cancel.) Both buttons have a Background image set in Interface Builder.

正在处理取消按钮的背景图像的方式有问题。使用NSZombieEnabled,我一直在运行该程序。通常,下面的方法记录下:

Something is wrong with the way the background image for the cancel button is being handled. With NSZombieEnabled, I've been running the program. Most often, the method below logs this:

-[ModalDialog showInView:title:message:cancelText:proceedText:]
dialogProceedButton <UIButton: 0x7031f10; frame = (286 192; 90 31) // (etc.)
dialogProceedButtonBackground <UIImage: 0x3b36120>
dialogCancelButton <UIButton: 0x3b39cd0; frame = (104 192; 90 31) // (etc.)
dialogCancelButtonBackground <UIImage: 0x3b3a920>

这是完全正常的。但是,有时它会这样做(如果我通过快速点击一些界面按钮来抢占用户界面,我可以稍微可靠地重复这一点):

That's completely normal. However, sometimes it does this (I can get this to repeat somewhat reliably if I "rush" the UI by rapid tapping some interface buttons):

-[ModalDialog showInView:title:message:cancelText:proceedText:]
dialogProceedButton <UIButton: 0x7031f10; frame = (286 192; 90 31) // (etc.)
dialogProceedButtonBackground <UIImage: 0x3b36120>
dialogCancelButton <UIButton: 0x3b39cd0; frame = (104 192; 90 31) // (etc.)
*** -[UIImage retain]: message sent to deallocated instance 0x3b3a920

如您所见,NSZombieEnabled发现取消按钮的背景图像已被解除分配,但正在发送保留消息。 (不是我,但是......那个图像用于这个按钮,并且在Interface Builder中访问。我没有任何IBOutlets或任何变量链接到该图像。)

As you can see, NSZombieEnabled found that the background image for the Cancel button has been deallocated, but is being sent a retain message. (Not by me, though... that image is only used for this one button, and only accessed in Interface Builder. I don't have any IBOutlets or any variables linked to that image.)

那么,嗯,现在怎么办?

So, um, what now?

有时,它不是一个被保留为僵尸的保留消息,有时它是isKindOfClass:

Sometimes, it's not a retain message that gets caught as a zombie, sometimes it's isKindOfClass:

//(the object address is always dialogCancelButton.currentBackgroundImage)
-[UIImage isKindOfClass:]: message sent to deallocated instance 0x1661f0
//occasionally, these come along, too:
*** NSInvocation: warning: object 0x7e0d0b0 of class '_NSZombie_UIImage' does not implement methodSignatureForSelector: -- trouble ahead
*** NSInvocation: warning: object 0x7e0d0b0 of class '_NSZombie_UIImage' does not implement doesNotRecognizeSelector: -- abort

这是我的自定义UIViewsshowInView方法:

This is my custom UIViews "showInView" method:

- (void)showInView:superView 
             title:(NSString*)title 
             message:(NSString*)message 
             cancelText:(NSString*)cancelText 
             proceedText:(NSString*)proceedText {

NSLog(@"%s",__PRETTY_FUNCTION__);
NSLog(@"dialogProceedButton %@", dialogProceedButton);
NSLog(@"dialogProceedButtonBackground %@", dialogProceedButton.currentBackgroundImage);
NSLog(@"dialogCancelButton %@", dialogCancelButton);
NSLog(@"dialogCancelButtonBackground %@", dialogCancelButton.currentBackgroundImage);



CGRect rect;
dialogTitle.text = title;
dialogMessage.text = message;
[dialogProceedButton setTitle:proceedText forState:UIControlStateNormal];

if (cancelText == @"") { // SINGLE BUTTON DIALOG
  dialogCancelButton.hidden = YES;
  rect = [dialogProceedButton frame];
  rect.origin.x = 195; //center the button 
  [dialogProceedButton setFrame:rect];
} else {
  [dialogCancelButton setTitle:cancelText forState:UIControlStateNormal];
  dialogCancelButton.hidden = NO;
  rect = [dialogProceedButton frame];
  rect.origin.x = 286; //button on right of dialog box 
  [dialogProceedButton setFrame:rect];
}

[UIView beginAnimations:@"modalAppears" context:nil];
[UIView setAnimationDuration:0.5];
[superView addSubview:self];
self.alpha = 1.0;
[UIView commitAnimations];
}

谢谢!

推荐答案

好的,这个是什么的。我决定尝试反转Proceed和Cancel按钮的图像。结果是,继续按钮图像会导致崩溃(就像间歇性一样)。我完全删除了我的项目和Interface Builder中的图像。然后我添加了一个带有新名称的新副本并将其连接起来。

Ok, this one's a what-the-heck. I decided to try reversing the images for the Proceed and Cancel buttons. The result was now that the Proceed button image would cause the crash (just as intermittently). I completely deleted the image from my project and from Interface Builder. I then added a fresh copy with a new name and hooked it up.

使用之前的设置,我能够在大约40%的时间内重现崩溃。在这些更改后我已经尝试了大约20次来重现崩溃,现在我无法重现它。

With the previous setup, I had been able to reproduce the crash about 40% of the time. I've tried about 20 times to reproduce the crash after these changes, and I cannot reproduce it at all now.

如果图像或笔尖已损坏,为什么,为什么,为什么会引起随机/间歇性症状呢?

If the image or the nib was corrupted, why, why, why would it cause a random/intermittent symptom?

什么是蠢货。希望它能够很好地修复。

Whattathing. Hope it's well and truly fixed.

并且......所以还有更多内容。结果我发现我巧合地在我的(不完整的)指令视图中使用与占位符相同的图像。为了临时方便,我使用[UIImage imageNamed:]来抓取图像。它被正确分配和发布,但似乎IB与imageNamed:方法和/或缓存的合作并不完美。

And... so there is a bit more to it. Turns out I discovered that I had coincidentally been using the same image as a placeholder in my (incomplete) instructions view. For temporary convenience there, I was using [UIImage imageNamed:] to grab the image. It was being properly allocated and released, but it seems that IB's cooperation with the imageNamed: method and/or cache is not perfect.

当我去抓住时的事实一个新的图像副本,我还给它一个新的名称,意味着现在IB按钮图像和临时占位符图像根本不再是相同的图像。

The fact that when I went and grabbed a fresh copy of the image, I also gave it a new name, meant that now the IB button image and the temporary placeholder image were no longer the same image at all.

我几天前回到我的项目备份来测试我的理论。我所做的只是告诉说明视图使用不同的占位符图像。崩溃停止了。

I went back to a backup of my project from a couple days ago to test my theory. All I did was tell the instructions view to use a different placeholder image. Crashes stopped.

这可能是一个SDK错误。不应该有任何理由不在IB中使用图像,也可以使用imageNamed在其他地方使用相同的图像:如果我在这些日子里感到狡猾或无聊,也许我会把它提炼成一个示例项目发送到Apple雷达。

This is probably an SDK bug, then. There shouldn't be any reason not to use an image in IB and also use the same image elsewhere using imageNamed:. If I feel wily or bored one of these days, maybe I'll distill this down into an example project to send to Apple radar.

这篇关于由Interface Builder创建的UIButton正在崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆