3

我已经缩小了一个丑陋的错误,但由于它看起来像是 nib/Interface Builder 内部的东西,我不知道下一步该做什么。

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

处理取消按钮的背景图像的方式有问题。使用 NSZombieEnabled,我一直在运行该程序。大多数情况下,以下方法会记录以下内容:

-[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>

这是完全正常的。然而,有时它会这样做(如果我通过快速点击一些界面按钮来“冲”UI,我可以让它在某种程度上可靠地重复):

-[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 或任何链接到该图像的变量。)

那么,嗯,现在呢?

编辑:

有时,它不是作为僵尸捕获的保留消息,有时是 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

这是我的自定义 UIViews “showInView” 方法:

- (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];
}

谢谢!

4

2 回答 2

3

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

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

如果图像或笔尖损坏,为什么,为什么,为什么会导致随机/间歇性症状?

什么。希望它得到很好的真正修复。


更新:

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

当我去抓取图像的新副本时,我也给它起了一个新名称,这意味着现在 IB 按钮图像和临时占位符图像不再是同一个图像了。

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

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

于 2009-10-16T00:22:06.517 回答
0

您的 XIB 文件是如何连接到您的视图的?您定义了哪些 IBOutlets?我真的怀疑你是否以你描述的方式解决了你的问题。

于 2009-10-16T05:31:58.800 回答