代码之家  ›  专栏  ›  技术社区  ›  Rob

界面生成器创建的UIButton正在崩溃

  •  3
  • Rob  · 技术社区  · 15 年前

    我已经缩小了一个丑陋的bug的范围,但是由于它看起来像是nib/接口生成器内部的东西,我不知道下一步该怎么做。

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

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

    只有 用于此一个按钮,以及 只有 在界面生成器中访问。我没有任何IBOutlets或任何变量链接到该图像。)

    那现在呢?

    编辑:

    有时,它不是一条被当作僵尸捕获的保留消息,有时它是一种类别:

    //(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
    

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

    谢谢

    2 回复  |  直到 15 年前
        1
  •  3
  •   Rob    15 年前

    好吧,这是一个什么鬼东西。我决定尝试反转“继续”和“取消”按钮的图像。结果是现在 继续

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

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

    什么事。希望它是好的和真正的修复。


    事实上,当我去拿一张新的图片时,我也给了它一张新的 名称

    那么,这可能是一个SDK错误。没有任何理由不在IB中使用图像,也可以在其他地方使用相同的图像,使用ImageName:。如果有一天我觉得自己很狡猾或无聊,也许我会将其提炼成一个示例项目,发送给苹果雷达。

        2
  •  0
  •   Kendall Helmstetter Gelner    15 年前

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