ฉันได้จำกัดข้อผิดพลาดที่น่าเกลียดให้แคบลงแล้ว แต่เนื่องจากดูเหมือนว่ามีบางอย่างอยู่ภายใน nib/Interface Builder ฉันจึงไม่รู้ว่าจะต้องทำอย่างไรต่อไป
ฉันมี UIView ที่สร้างใน IB ซึ่งทำหน้าที่เป็นกล่องโต้ตอบที่กำหนดเอง มันแสดงข้อความและปุ่มสองปุ่ม (ดำเนินการต่อหรือยกเลิก) ปุ่มทั้งสองมีการตั้งค่าภาพพื้นหลังในตัวสร้างอินเทอร์เฟซ
มีบางอย่างผิดปกติกับวิธีการจัดการภาพพื้นหลังของปุ่มยกเลิก ด้วย 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 พบว่าภาพพื้นหลังสำหรับปุ่มยกเลิกได้รับการจัดสรรคืนแล้ว แต่กำลังส่งข้อความเก็บรักษา (ไม่ใช่โดยฉันเอง... รูปภาพนั้น เท่านั้น ใช้สำหรับปุ่มนี้ และ เท่านั้น เข้าถึงได้ในตัวสร้างอินเทอร์เฟซ ฉันไม่มี 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
นี่คือวิธี "showInView" UIViews ที่กำหนดเองของฉัน:
- (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];
}
ขอบคุณ!