我已經將類對象添加到了nib文件中。所有連接都已完成。自定義類在應用程序啓動後立即釋放
但由於某種原因,只要創建對象就會釋放該對象。
下面的代碼:
control.h:
#import <Foundation/Foundation.h>
@interface control : NSObject
{
IBOutlet UILabel *PlayerScore;
}
-(IBAction) addPoint: sender;
-(void) dealloc;
@end
control.m:
#import "control.h"
@implementation control
-(IBAction)addPoint: sender {
NSLog(@"Ohhai. Didn't crash."); //Doesn't even make it to this stage.
int i = [PlayerScore.text intValue];
PlayerScore.text=[NSString stringWithFormat: @"%d",++i];
}
-(void) dealloc {
NSLog(@"ZOMGWTF?");
[super dealloc];
}
@end
這裏是控制檯日誌:
[會話開始於2010-06-09 19:47:57 +1000。]
2010-06-09 19:47:58.771 App [91100:207] ZOMGWTF?
而我點擊按鈕後,addPoint的消息當然會崩潰。
2010-06-09 19:47:59.703應用[91100:207] *** - [控制] performSelector:withObject:withObject:]:消息發送到釋放的實例0x3843d80
不有人有主意嗎?
試過,但仍然在運行時解除分配。 控制器沒有連接參考插座。 – tangrs 2010-06-09 10:45:25
將引用連接到文件所有者...我假設您正在使用垃圾收集器進行構建。沒有提及將GC的「控制」對象持續掃除。 – 2010-06-10 09:57:36