UIButton, created by Interface Builder, collapses

I narrowed down the ugly bug, but since it seems to be something internal to nib / Interface Builder, I don’t understand what to do next.

I have a UIView created in IB that functions as a custom dialog. It shows a message and two buttons. (Continue or Cancel.) Both buttons have a background image set in Interface Builder.

Something is wrong with how the background image for the cancel button is processed. With NSZombieEnabled, I run 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>

This is completely normal. However, sometimes he does this (I can make it repeat somewhat reliably if I "rush" with the user interface by quickly pressing 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 , .)

, , ?

EDIT:

, , KindOfClass:

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

!

+3
2

, -. "" "". , ( ). Builder. .

40% . 20 , , .

, , , / ?

Whattathing. , .


:

... . , , , () . [UIImage imageNamed:], . , , IB imageNamed: method / .

, , , , IB .

, . , , - , . .

, , SDK. IB, imageNamed:. , , Apple.

+3

XIB ? IBOutlets ? , , .

0

Source: https://habr.com/ru/post/1720239/


All Articles